Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. long day = 86400000; // 86400000 milliseconds in a day
  2. long hour = 3600000; // 3600000 milliseconds in an hour
  3. long minute = 60000; // 60000 milliseconds in a minute
  4. long second = 1000; // 1000 milliseconds in a second
  5.  
  6. void setup(){
  7. Serial.begin (57600);
  8. }
  9.  
  10. void loop(){
  11. time();
  12. delay(1000);
  13. }
  14.  
  15. void time(){
  16. long timeNow = millis();
  17.  
  18. int days = timeNow / day ; //number of days
  19. int hours = (timeNow % day) / hour; //the remainder from days division (in milliseconds) divided by hours, this gives the full hours
  20. int minutes = ((timeNow % day) % hour) / minute ; //and so on...
  21. int seconds = (((timeNow % day) % hour) % minute) / second;
  22.  
  23. // digital clock display of current time
  24. Serial.print(days,DEC);
  25. printDigits(hours);
  26. printDigits(minutes);
  27. printDigits(seconds);
  28. Serial.println();
  29.  
  30. }
  31.  
  32. void printDigits(byte digits){
  33. // utility function for digital clock display: prints colon and leading 0
  34. Serial.print(":");
  35. if(digits < 10)
  36. Serial.print('0');
  37. Serial.print(digits,DEC);
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement