Created
August 16, 2015 13:06
-
-
Save kendx/42296a844ff8fe866818 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Simple Arduino Clock using Old DVD Player Display | |
* www.KendrickTabi.com | |
* http://www.kendricktabi.com/2015/05/simple-arduino-clock-using-old-dvd-display.html | |
*/ | |
#include <Time.h> | |
#include <SevSeg.h> | |
float time; | |
SevSeg sevseg; | |
byte numDigits = 6; // Number of digits used | |
byte digitPins[] = {10, 9, 8, 7, 6, 5}; | |
byte segmentPins[] = {21, 20, 19, 18, 15, 14, 16, 22}; | |
void setup() { | |
pinMode(2, INPUT_PULLUP); // The three pins to set the time manually | |
pinMode(3, INPUT_PULLUP); | |
pinMode(4, INPUT_PULLUP); | |
Serial.begin(9600); | |
while (Serial) ; // For Leonardo | |
Serial.println("Simple Arduino Clock using Old DVD Player Display"); // Debug | |
setTime(0, 0, 0, 5, 10, 15); // HH:MM:SS MM-DD-YY | |
sevseg.begin(COMMON_ANODE, numDigits, digitPins, segmentPins); | |
sevseg.setBrightness(50); // Will act as current limitor | |
} | |
void loop() { | |
xtime(); | |
digitalClockDisplay(); | |
segmentDisplay(); | |
Serial.println(time); | |
sevseg.refreshDisplay(); | |
} | |
void digitalClockDisplay() { | |
Serial.print(hour()); | |
printDigits(minute()); | |
printDigits(second()); | |
Serial.println(); | |
} | |
void printDigits(int digits) { | |
Serial.print(":"); | |
if(digits < 10) | |
Serial.print('0'); | |
Serial.print(digits); | |
} | |
void segmentDisplay() { | |
time = hour() * 0.01; | |
time += minute() * 0.0001; | |
time += second() * 0.000001; | |
sevseg.setNumber(time, 6); | |
} | |
void xtime(){ | |
if (digitalRead(2) == LOW) { | |
adjustTime(3600); // increment by 1 hour | |
Serial.println("+ Hr"); | |
delay(300); | |
} | |
if (digitalRead(3) == LOW) { | |
adjustTime(60); // increment by 1 minute | |
Serial.println("+ Min"); | |
delay(300); | |
} | |
if (digitalRead(4) == LOW) { | |
adjustTime(-60); // decrement by 1 miinute | |
Serial.println("- Min"); | |
delay(300); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment