Devices & Components
Arduino Uno Rev3
KYX-5461AS 4-digit 7-segment
Breadboard (generic)
Resistor 1k ohm
Real Time Clock (RTC)
Jumper wires (generic)
Project description
Code
DaysCounter.ino
c_cpp
for this you will need to download arduino IDE RTC library zip file, seven segment zip file save both of the libraries into the librarys folder where the arduino ide is installed. from there open up arduino ide and click on 'sketch' 'include libraries' 'add zip libraries' follow the code below TO ADJUST TIME - on line 7 in the brackets it reads (2017, 12 , 9, 0, 0, 0,) you need to change the first 3 numbers i.e 2017, 12, 9 ----> 2014, 4, 6, what ever date you got together, enter it there. then compile and select upload and if everything has gone to plan and you've followed the steps correctly it should display the amount of days you have been together
1#include <RTClib.h> 2#include <SevSeg.h> 3 4SevSeg sevseg; //Instantiate a seven segment controller object 5RTC_DS3231 rtc; 6 7DateTime dtBegin (2017, 12, 9, 0, 0, 0); //!!!! adjust time here!!!!! 8TimeSpan tsPassed; 9 10void showInfo(const DateTime& dt) { 11 Serial.print("NOW:"); 12 13 Serial.print(dt.year(), DEC); 14 Serial.print('/'); 15 Serial.print(dt.month(), DEC); 16 Serial.print('/'); 17 Serial.print(dt.day(), DEC); 18 Serial.print(' '); 19 Serial.print(dt.hour(), DEC); 20 Serial.print(':'); 21 Serial.print(dt.minute(), DEC); 22 Serial.print(':'); 23 Serial.print(dt.second(), DEC); 24 25 Serial.print("\ PASSED:"); 26 Serial.print(tsPassed.days(), DEC); 27 Serial.print(' '); 28 Serial.print(tsPassed.hours(), DEC); 29 Serial.print(':'); 30 Serial.print(tsPassed.minutes(), DEC); 31 Serial.print(':'); 32 Serial.print(tsPassed.seconds(), DEC); 33 34 Serial.println(""); 35} 36 37//========================================= 38// 39//========================================= 40void delayWithUpdate(uint32_t parDelay){ 41 uint32_t started=millis(); 42 while (millis()< started+parDelay){ 43 sevseg.refreshDisplay(); 44 } 45} 46//========================= 47//========================= 48void setup(){ 49 Serial.begin(9600); 50 Serial.println(__TIME__); 51 52 if (! rtc.begin()) { 53 Serial.println("Couldn't find RTC"); 54 //===Device will be frozen here. 55 //?????????May be some error LED blinking would be good to use?????? 56 while (1); 57 } 58 59 delay(1000); 60 61 //!!!!! TO ADJUST A TIME: 62 //1) uncomment a line below (under those comments) 63 //2), upload the code again 64 //3) COMMENT line back 65 //4). uploand ONE MORE TIME 66 67 68 69rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); //line to adjust time 70 71 72 byte numDigits = 4; 73 byte digitPins[] = {7, 8, 9, 10}; 74 //SEG: A B C D E F G . 75 //PIN: 11 7 4 2 1 10 5 3 76 //ARDU: 2 3 4 5 11 12 13 6 77 //byte segmentPins[] = {2, 3, 4, 5, 11, 12, 13, 6}; 78 byte segmentPins[] = {2, 3, 4, 5, 11, 12, 13, 6}; 79 bool resistorsOnSegments = false; // 'false' means resistors are on digit pins 80 byte hardwareConfig = COMMON_CATHODE; // See README.md for options 81 bool updateWithDelays = false; // Default 'false' is Recommended 82 bool leadingZeros = false; // Use 'true' if you'd like to keep the leading zeros 83 bool disableDecPoint = true; // Use 'true' if your decimal point doesn't exist or isn't connected 84 85 sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments, 86 updateWithDelays, leadingZeros, disableDecPoint); 87 sevseg.setBrightness(100); 88 89 90 91 sevseg.setNumber(1234, 1); 92 delayWithUpdate(1000); 93 94 95 sevseg.setNumber(8888, 1); 96 delayWithUpdate(1000); 97 98} 99//========================= 100//========================= 101void loop(){ 102 sevseg.refreshDisplay(); 103 104 DateTime now = rtc.now(); 105 106 tsPassed = now-dtBegin; 107 108 static uint32_t nextReportMillis=0; 109 static uint16_t prevDaysPassed=0; 110 111 if (tsPassed.days() != prevDaysPassed){ 112 prevDaysPassed=tsPassed.days(); 113 sevseg.setNumber(prevDaysPassed, 0); 114 } 115 116 117 sevseg.refreshDisplay(); 118 119 if (millis()>nextReportMillis){ 120 //===PRINT SOME INFO HERE 121 showInfo(now); 122 nextReportMillis=millis()+5000; 123 } 124 125} 126
DaysCounter.ino
c_cpp
for this you will need to download arduino IDE RTC library zip file, seven segment zip file save both of the libraries into the librarys folder where the arduino ide is installed. from there open up arduino ide and click on 'sketch' 'include libraries' 'add zip libraries' follow the code below TO ADJUST TIME - on line 7 in the brackets it reads (2017, 12 , 9, 0, 0, 0,) you need to change the first 3 numbers i.e 2017, 12, 9 ----> 2014, 4, 6, what ever date you got together, enter it there. then compile and select upload and if everything has gone to plan and you've followed the steps correctly it should display the amount of days you have been together
1#include <RTClib.h> 2#include <SevSeg.h> 3 4SevSeg sevseg; //Instantiate 5 a seven segment controller object 6RTC_DS3231 rtc; 7 8DateTime dtBegin (2017, 9 12, 9, 0, 0, 0); //!!!! adjust time here!!!!! 10TimeSpan tsPassed; 11 12void 13 showInfo(const DateTime& dt) { 14 Serial.print("NOW:"); 15 16 Serial.print(dt.year(), 17 DEC); 18 Serial.print('/'); 19 Serial.print(dt.month(), DEC); 20 Serial.print('/'); 21 22 Serial.print(dt.day(), DEC); 23 Serial.print(' '); 24 Serial.print(dt.hour(), 25 DEC); 26 Serial.print(':'); 27 Serial.print(dt.minute(), DEC); 28 Serial.print(':'); 29 30 Serial.print(dt.second(), DEC); 31 32 Serial.print("\ PASSED:"); 33 Serial.print(tsPassed.days(), 34 DEC); 35 Serial.print(' '); 36 Serial.print(tsPassed.hours(), DEC); 37 Serial.print(':'); 38 39 Serial.print(tsPassed.minutes(), DEC); 40 Serial.print(':'); 41 Serial.print(tsPassed.seconds(), 42 DEC); 43 44 Serial.println(""); 45} 46 47//========================================= 48// 49//========================================= 50void 51 delayWithUpdate(uint32_t parDelay){ 52 uint32_t started=millis(); 53 while (millis()< 54 started+parDelay){ 55 sevseg.refreshDisplay(); 56 } 57} 58//========================= 59//========================= 60void 61 setup(){ 62 Serial.begin(9600); 63 Serial.println(__TIME__); 64 65 if (! 66 rtc.begin()) { 67 Serial.println("Couldn't find RTC"); 68 //===Device 69 will be frozen here. 70 //?????????May be some error LED blinking would 71 be good to use?????? 72 while (1); 73 } 74 75 delay(1000); 76 77 78 //!!!!! TO ADJUST A TIME: 79 //1) uncomment a line below (under those 80 comments) 81 //2), upload the code again 82 //3) COMMENT line back 83 //4). 84 uploand ONE MORE TIME 85 86 87 88rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); 89 //line to adjust time 90 91 92 byte numDigits = 4; 93 byte digitPins[] 94 = {7, 8, 9, 10}; 95 //SEG: A B C D E F G . 96 //PIN: 11 7 4 2 1 10 5 3 97 98 //ARDU: 2 3 4 5 11 12 13 6 99 //byte segmentPins[] = {2, 3, 4, 5, 11, 12, 100 13, 6}; 101 byte segmentPins[] = {2, 3, 4, 5, 11, 12, 13, 6}; 102 bool resistorsOnSegments 103 = false; // 'false' means resistors are on digit pins 104 byte hardwareConfig = 105 COMMON_CATHODE; // See README.md for options 106 bool updateWithDelays = false; 107 // Default 'false' is Recommended 108 bool leadingZeros = false; // Use 'true' 109 if you'd like to keep the leading zeros 110 bool disableDecPoint = true; // Use 111 'true' if your decimal point doesn't exist or isn't connected 112 113 sevseg.begin(hardwareConfig, 114 numDigits, digitPins, segmentPins, resistorsOnSegments, 115 updateWithDelays, leadingZeros, 116 disableDecPoint); 117 sevseg.setBrightness(100); 118 119 120 121 sevseg.setNumber(1234, 122 1); 123 delayWithUpdate(1000); 124 125 126 sevseg.setNumber(8888, 1); 127 128 delayWithUpdate(1000); 129 130} 131//========================= 132//========================= 133void 134 loop(){ 135 sevseg.refreshDisplay(); 136 137 DateTime now = rtc.now(); 138 139 140 tsPassed = now-dtBegin; 141 142 static uint32_t nextReportMillis=0; 143 static 144 uint16_t prevDaysPassed=0; 145 146 if (tsPassed.days() != prevDaysPassed){ 147 148 prevDaysPassed=tsPassed.days(); 149 sevseg.setNumber(prevDaysPassed, 0); 150 151 } 152 153 154 sevseg.refreshDisplay(); 155 156 if (millis()>nextReportMillis){ 157 158 //===PRINT SOME INFO HERE 159 showInfo(now); 160 nextReportMillis=millis()+5000; 161 162 } 163 164} 165
Downloadable files
SCHEMATIC
https://www.circuito.io/app?components=512,11021] copy and paste the link. click add components type; RTC (add); 7 segment display 20mm (choose generic, don't choose sparkfun); follow the diagram and attach each pin using the jumper cables
SCHEMATIC

Comments
Only logged in users can leave comments