/* Set Millis v2 David Johnson-Davies - www.technoblogy.com - 14th May 2016 CC BY 4.0 Licensed under a Creative Commons Attribution 4.0 International license: http://creativecommons.org/licenses/by/4.0/ */ #include "wiring.c" const int Adjust = 8; void SetMillis () { char T[] = __TIME__; uint8_t oldSREG = SREG; cli(); unsigned long temp = (unsigned long)((T[0]*10+T[1]-528)*60+T[3]*10+T[4]-528)*60 +T[6]*10+T[7]-528+Adjust; timer0_millis = (unsigned long)temp*1000; SREG = oldSREG; } void setup() { SetMillis(); // initialize serial communication Serial.begin(9600); } // Add a leading zero when necessary void Print2 (int n) { if (n<10) Serial.print('0'); Serial.print(n); } void loop() { // Demonstrate clock unsigned long Now = millis()/1000; int Seconds = Now%60; int Minutes = (Now/60)%60; int Hours = (Now/3600)%24; Print2(Hours); Serial.print(':'); Print2(Minutes); Serial.print(':'); Print2(Seconds); Serial.println(); delay(1000); }