Skip to content

Instantly share code, notes, and snippets.

@kachurovskiy
Created February 11, 2016 22:18
Show Gist options
  • Save kachurovskiy/e2b507559bdd6893833a to your computer and use it in GitHub Desktop.
Save kachurovskiy/e2b507559bdd6893833a to your computer and use it in GitHub Desktop.
Arduino program showing data from DS1302 clock on 4-digit display
#include <virtuabotixRTC.h>
#include <SevSeg.h>
SevSeg sevseg;
// Clock DS1302 on analog pins 0 to 2
virtuabotixRTC myRTC(14, 15, 16);
void setup() {
byte numDigits = 4;
// 4-digit display HS420561K-32 on digital pins 2 to 13
byte digitPins[] = {2, 3, 4, 5};
byte segmentPins[] = {6, 7, 8, 9, 10, 11, 12, 13};
sevseg.begin(COMMON_CATHODE, numDigits, digitPins, segmentPins);
sevseg.setBrightness(90);
// Comment out on second run if clock has 3V battery.
myRTC.setDS1302Time(40, 13, 23, 3, 11, 2, 2016);
}
void loop() {
myRTC.updateTime();
sevseg.setNumber(myRTC.hours * 100 + myRTC.minutes, 2);
sevseg.refreshDisplay();
delay(10); // Optional, to save power.
}
@BorkoTosic
Copy link

Hi, sir i just tried out the code and its working partially.When I disconnect the Arduino from the power and connect it again the time resets and shows the default value on sevseg.How can I solve the problem?I bought a a new 3v battery but that wasnt the problem. Anyway thanks!

@kachurovskiy
Copy link
Author

Hi, sir i just tried out the code and its working partially.When I disconnect the Arduino from the power and connect it again the time resets and shows the default value on sevseg.How can I solve the problem?I bought a a new 3v battery but that wasnt the problem. Anyway thanks!

See comment on line 18. You might want to comment out line 19.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment