Arduino DIY Clock
Arduino DIY Clock with energy saving mode and a 3D printed case!
Components and supplies
1
Arduino Nano R3
1
Real Time Clock (RTC)
Tools and machines
1
Soldering iron (generic)
1
3D Printer (generic)
Apps and platforms
1
Arduino IDE
Project description
Code
The code:
c_cpp
1/* 2 * 1.0 3 * : 1.4 4 * : 5*/ 6 7#include <LowPower.h> 8#include <Adafruit_GFX_rus.h> 9#include <Adafruit_PCD8544_rus.h> 10Adafruit_PCD8544 nokia = Adafruit_PCD8544(4, 3, 6, 7, 8); //CLK, DIN, DC, CE, RST 11 12/* 13 * : 14 * 15 * --> 16 *(1)RST --> 8 pin 17 *(2)CE --> 7 pin 18 *(3)DC --> 6 pin 19 *(4)DIN --> 3 pin 20 *(5)CLK --> 4 pin 21 *(6)VCC --> 10 pin !!! !!! 22 *(7)LIGHT --> ----- ( . 23 * . .) 24 *(8)GND --> GND 25 * 26 * 2 . 27 * 28*/ 29 30/* 31 * : 32 * IC: 33 * --> 34 * SDA --> A4 35 * SCL --> A5 36 * ==== ==== 37 * VCC --> 3.3V 38 * GND --> GND 39*/ 40 41extern uint8_t logo[]; 42 43#include <iarduino_RTC.h> // iarduino_RTC . 44iarduino_RTC time(RTC_DS1307); // time RTC DS3231, I2C 45 46//================= =================== 47volatile int sec = 15; 48volatile int minute = 8; 49volatile int hour = 15; 50volatile int date = 22; 51volatile int Month = 6; 52volatile int Year = 18; 53volatile int weekDay = 5; 54//================================================== 55 56 57int day; 58int month; 59volatile boolean sleep = false; 60 61#define powerBtn 2 62#define dispPower 10 63 64void setup() { 65 delay(3000); // ! 5. 66 // , 5 67 pinMode(dispPower, OUTPUT); 68 digitalWrite(dispPower, HIGH); 69 pinMode(powerBtn, INPUT_PULLUP); 70 71 delay(300); // 72 time.begin(); // . 73 time.settime(sec,minute,hour,date,Month,Year,weekDay); // : 0 , 51 , 21 , 27, , 2015 , . 74 75 nokia.begin(); 76 nokia.clearDisplay(); 77 nokia.setContrast(55); 78 nokia.drawBitmap(0, 0, logo, 84, 48, BLACK); // Pe 79 nokia.display(); 80 delay(1500); 81 nokia.clearDisplay(); 82 nokia.drawLine(0, 20, 84, 20, BLACK); 83 nokia.display(); 84} 85 86//========== !!! ========= 87void wake_up() { 88 digitalWrite(dispPower, HIGH); 89 sleep = false; 90 nokia.begin(); 91 nokia.clearDisplay(); 92 nokia.setContrast(55); 93 nokia.display(); 94 detachInterrupt(0); 95 nokia.drawBitmap(0, 0, logo, 84, 48, BLACK); // Pe 96 nokia.display(); 97} 98//=========================================================== 99 100void loop() { 101 //========== ========== 102 if (sleep == false && digitalRead(powerBtn) == 0) { 103 nokia.clearDisplay(); 104 nokia.drawBitmap(0, 0, logo, 84, 48, BLACK); // Pe 105 nokia.display(); 106 delay(1000); 107 digitalWrite(dispPower, LOW); 108 sleep = true; 109 delay(1000); 110 attachInterrupt(0, wake_up, LOW); 111 if (sleep == true) {LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);} 112 } 113 //========================================================================= 114 115 LowPower.powerDown(SLEEP_250MS, ADC_OFF, BOD_OFF); // 250 116 117 //========== ========== 118 nokia.clearDisplay(); 119 nokia.drawLine(4, 25, 80, 25, BLACK); // 120 time.gettime(); // 121 nokia.setTextSize(2); // 2 122 nokia.setCursor(5,5); // (5 5 y) 123 nokia.print(time.Hours); // 124 nokia.setTextSize(3); // 3 125 nokia.setCursor(25,2); // 126 nokia.print(":"); 127 nokia.setTextSize(2); 128 nokia.setCursor(40,5); 129 nokia.print(time.minutes); // 130 nokia.setTextSize(1); 131 nokia.setCursor(68,5); 132 nokia.print(time.seconds); // 133 //===================================== 134 135 //================ =================== 136 nokia.setCursor(13,30); 137 time.gettime(); 138 //================ ))) ================= 139 day = time.weekday; 140 switch (day) { 141 case 0: 142 nokia.print(","); 143 break; 144 case 1: 145 nokia.print(","); 146 break; 147 case 2: 148 nokia.print(","); 149 break; 150 case 3: 151 nokia.print(","); 152 break; 153 case 4: 154 nokia.print(","); 155 break; 156 case 5: 157 nokia.print(","); 158 break; 159 case 6: 160 nokia.print(","); 161 break; 162 } 163 //==================================================== 164 nokia.setCursor(40,30); 165 nokia.print(time.gettime("d.m")); 166 nokia.setCursor(10,40); 167 month = time.month; 168 switch (month) { 169 case 1: 170 nokia.print(", "); 171 break; 172 case 2: 173 nokia.print(", "); 174 break; 175 case 3: 176 nokia.print(", "); 177 break; 178 case 4: 179 nokia.print(", "); 180 break; 181 case 5: 182 nokia.print(", "); 183 break; 184 case 6: 185 nokia.print(", "); 186 break; 187 case 7: 188 nokia.print(", "); 189 break; 190 case 8: 191 nokia.print(", "); 192 break; 193 case 9: 194 nokia.print(", "); 195 break; 196 case 10: 197 nokia.print(", "); 198 break; 199 case 11: 200 nokia.print(", "); 201 break; 202 case 12: 203 nokia.print(", "); 204 break; 205 } 206 207 nokia.print(time.gettime("Y")); 208 //=================================================== 209 210 nokia.display(); 211} 212 213 214 215
The code:
c_cpp
1/* 2 * 1.0 3 * : 1.4 4 * : 5*/ 6 7#include <LowPower.h> 8#include <Adafruit_GFX_rus.h> 9#include <Adafruit_PCD8544_rus.h> 10Adafruit_PCD8544 nokia = Adafruit_PCD8544(4, 3, 6, 7, 8); //CLK, DIN, DC, CE, RST 11 12/* 13 * : 14 * 15 * --> 16 *(1)RST --> 8 pin 17 *(2)CE --> 7 pin 18 *(3)DC --> 6 pin 19 *(4)DIN --> 3 pin 20 *(5)CLK --> 4 pin 21 *(6)VCC --> 10 pin !!! !!! 22 *(7)LIGHT --> ----- ( . 23 * . .) 24 *(8)GND --> GND 25 * 26 * 2 . 27 * 28*/ 29 30/* 31 * : 32 * IC: 33 * --> 34 * SDA --> A4 35 * SCL --> A5 36 * ==== ==== 37 * VCC --> 3.3V 38 * GND --> GND 39*/ 40 41extern uint8_t logo[]; 42 43#include <iarduino_RTC.h> // iarduino_RTC . 44iarduino_RTC time(RTC_DS1307); // time RTC DS3231, I2C 45 46//================= =================== 47volatile int sec = 15; 48volatile int minute = 8; 49volatile int hour = 15; 50volatile int date = 22; 51volatile int Month = 6; 52volatile int Year = 18; 53volatile int weekDay = 5; 54//================================================== 55 56 57int day; 58int month; 59volatile boolean sleep = false; 60 61#define powerBtn 2 62#define dispPower 10 63 64void setup() { 65 delay(3000); // ! 5. 66 // , 5 67 pinMode(dispPower, OUTPUT); 68 digitalWrite(dispPower, HIGH); 69 pinMode(powerBtn, INPUT_PULLUP); 70 71 delay(300); // 72 time.begin(); // . 73 time.settime(sec,minute,hour,date,Month,Year,weekDay); // : 0 , 51 , 21 , 27, , 2015 , . 74 75 nokia.begin(); 76 nokia.clearDisplay(); 77 nokia.setContrast(55); 78 nokia.drawBitmap(0, 0, logo, 84, 48, BLACK); // Pe 79 nokia.display(); 80 delay(1500); 81 nokia.clearDisplay(); 82 nokia.drawLine(0, 20, 84, 20, BLACK); 83 nokia.display(); 84} 85 86//========== !!! ========= 87void wake_up() { 88 digitalWrite(dispPower, HIGH); 89 sleep = false; 90 nokia.begin(); 91 nokia.clearDisplay(); 92 nokia.setContrast(55); 93 nokia.display(); 94 detachInterrupt(0); 95 nokia.drawBitmap(0, 0, logo, 84, 48, BLACK); // Pe 96 nokia.display(); 97} 98//=========================================================== 99 100void loop() { 101 //========== ========== 102 if (sleep == false && digitalRead(powerBtn) == 0) { 103 nokia.clearDisplay(); 104 nokia.drawBitmap(0, 0, logo, 84, 48, BLACK); // Pe 105 nokia.display(); 106 delay(1000); 107 digitalWrite(dispPower, LOW); 108 sleep = true; 109 delay(1000); 110 attachInterrupt(0, wake_up, LOW); 111 if (sleep == true) {LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);} 112 } 113 //========================================================================= 114 115 LowPower.powerDown(SLEEP_250MS, ADC_OFF, BOD_OFF); // 250 116 117 //========== ========== 118 nokia.clearDisplay(); 119 nokia.drawLine(4, 25, 80, 25, BLACK); // 120 time.gettime(); // 121 nokia.setTextSize(2); // 2 122 nokia.setCursor(5,5); // (5 5 y) 123 nokia.print(time.Hours); // 124 nokia.setTextSize(3); // 3 125 nokia.setCursor(25,2); // 126 nokia.print(":"); 127 nokia.setTextSize(2); 128 nokia.setCursor(40,5); 129 nokia.print(time.minutes); // 130 nokia.setTextSize(1); 131 nokia.setCursor(68,5); 132 nokia.print(time.seconds); // 133 //===================================== 134 135 //================ =================== 136 nokia.setCursor(13,30); 137 time.gettime(); 138 //================ ))) ================= 139 day = time.weekday; 140 switch (day) { 141 case 0: 142 nokia.print(","); 143 break; 144 case 1: 145 nokia.print(","); 146 break; 147 case 2: 148 nokia.print(","); 149 break; 150 case 3: 151 nokia.print(","); 152 break; 153 case 4: 154 nokia.print(","); 155 break; 156 case 5: 157 nokia.print(","); 158 break; 159 case 6: 160 nokia.print(","); 161 break; 162 } 163 //==================================================== 164 nokia.setCursor(40,30); 165 nokia.print(time.gettime("d.m")); 166 nokia.setCursor(10,40); 167 month = time.month; 168 switch (month) { 169 case 1: 170 nokia.print(", "); 171 break; 172 case 2: 173 nokia.print(", "); 174 break; 175 case 3: 176 nokia.print(", "); 177 break; 178 case 4: 179 nokia.print(", "); 180 break; 181 case 5: 182 nokia.print(", "); 183 break; 184 case 6: 185 nokia.print(", "); 186 break; 187 case 7: 188 nokia.print(", "); 189 break; 190 case 8: 191 nokia.print(", "); 192 break; 193 case 9: 194 nokia.print(", "); 195 break; 196 case 10: 197 nokia.print(", "); 198 break; 199 case 11: 200 nokia.print(", "); 201 break; 202 case 12: 203 nokia.print(", "); 204 break; 205 } 206 207 nokia.print(time.gettime("Y")); 208 //=================================================== 209 210 nokia.display(); 211} 212 213 214 215
Downloadable files
Librarys
Librarys
Documentation
STL files
STL files
STL files
STL files
Comments
Only logged in users can leave comments