-
-
Save alexbarbosa/5416290 to your computer and use it in GitHub Desktop.
| #include <LiquidCrystal.h> | |
| LiquidCrystal lcd(8, 9, 4, 5, 6, 7); | |
| void setup() { | |
| lcd.print("What time is it?"); | |
| delay(1000); | |
| lcd.begin(16, 2); | |
| lcd.setCursor(0, 0); | |
| lcd.print("Apr, 15, 2013"); // print out the date | |
| } | |
| //thhis is a list of int variables used in this clock program | |
| int s=0; | |
| int sec=0; | |
| int hrs=0; | |
| int minutes=0; | |
| int initialHours = 02;//variable to initiate hours | |
| int initialMins = 0;//variable to initiate minutes | |
| int initialSecs = 00;//variable to initiate seconds | |
| //this method is for seconds | |
| int seconds() | |
| { | |
| s = initialHours*3600; | |
| s = s+(initialMins*60); | |
| s = s+initialSecs; | |
| s = s+(millis()/1000); | |
| return s; | |
| } | |
| //this method is for hours | |
| int hours() | |
| { | |
| hrs = seconds(); | |
| hrs = hrs/3600; | |
| hrs = hrs%24; | |
| return hrs; | |
| } | |
| //this method is for minutes | |
| int mins() | |
| { | |
| minutes = seconds(); | |
| minutes = minutes/60; | |
| minutes = minutes%60; | |
| return minutes; | |
| } | |
| int secs() | |
| { | |
| sec = seconds(); | |
| sec = sec%60; | |
| return sec; | |
| } | |
| //this loop will conintue to keep looping so that the time can go as follows | |
| void loop(){ | |
| digitalClockDisplay(); | |
| } | |
| void printDigits(byte digits){ | |
| if(digits < 10) | |
| lcd.print('0'); | |
| lcd.print(digits); | |
| } | |
| char sep() | |
| { | |
| s = millis()/1000; | |
| if(s%2==0) | |
| { | |
| lcd.print(":"); | |
| } | |
| else { | |
| lcd.print(" "); | |
| } | |
| } | |
| void digitalClockDisplay(){ | |
| lcd.setCursor(0,1); | |
| printDigits( | |
| hours()); | |
| sep(); | |
| printDigits(mins()); | |
| sep(); | |
| printDigits(secs()); | |
| } |
Is there something in it that changes month and year?
@harryson4 yes where it says the month year and day just change those
How do you set the initial time?
Just a note to others, as soon as the processor starts doing some work and processing stuff, the clock will get out of sync. Apart from that, I like the implementation. Come to think of it, having this run on a cheap Arduino nano as a dedicated clock could work nicely :)
bro its not working instead ill provide a better code for this programm mine give a delay of 5secs for every 12 hours
Nice project and it works. But how to set the initial time?
The time shows fine until 9:59:59. It goes from 9:59:59 to 248:243:236. Also, if I change the start time to (line 16) to 08 or 09, I get an error.
error: invalid digit "9" in octal constant
int initialHours = 09;//variable to initiate hours
I'm REALLY new at this so please don't explain it as if to an expert. Thanks
hey @alexbarbosa thanks for uploading this, perfect for my use case.