1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
HardwareSerial &pc = Serial; unsigned int totalSeconds, hours, minutes, seconds; void setup() { pc.begin(9600); while(!pc); pc.println("Contador de tiempo (H:M:S)"); } void loop() { totalSeconds = millis()/1000; hours = totalSeconds / 3600; minutes = totalSeconds % 3600 / 60; seconds = totalSeconds % 60; pc.print(hours < 10 ? "0" : ""); pc.print(hours); pc.print(":"); pc.print(minutes < 10 ? "0" : ""); pc.print(minutes); pc.print(":"); pc.print(seconds < 10 ? "0" : ""); pc.println(seconds); delay(1000); } |