Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- long day = 86400000; // 86400000 milliseconds in a day
- long hour = 3600000; // 3600000 milliseconds in an hour
- long minute = 60000; // 60000 milliseconds in a minute
- long second = 1000; // 1000 milliseconds in a second
- void setup(){
- Serial.begin (57600);
- }
- void loop(){
- time();
- delay(1000);
- }
- void time(){
- long timeNow = millis();
- int days = timeNow / day ; //number of days
- int hours = (timeNow % day) / hour; //the remainder from days division (in milliseconds) divided by hours, this gives the full hours
- int minutes = ((timeNow % day) % hour) / minute ; //and so on...
- int seconds = (((timeNow % day) % hour) % minute) / second;
- // digital clock display of current time
- Serial.print(days,DEC);
- printDigits(hours);
- printDigits(minutes);
- printDigits(seconds);
- Serial.println();
- }
- void printDigits(byte digits){
- // utility function for digital clock display: prints colon and leading 0
- Serial.print(":");
- if(digits < 10)
- Serial.print('0');
- Serial.print(digits,DEC);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement