Last active
February 27, 2019 14:39
-
-
Save rafalw/68cd18eaa096d81e8772826f9a375ee0 to your computer and use it in GitHub Desktop.
Ćwiczenie 1: pomiar czasu (program do modyfikacji – docelowo ma współpracować z LCD 16x2)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Timer.h> | |
#define N 2 | |
#define S 1000 | |
Timer t; | |
int sekundy = 0; | |
int minuty = 0; | |
int godziny = 0; | |
void setup() { | |
Serial.begin(115200); | |
t.every(N*1000, pokaz_czas, NULL); | |
t.every(S, pomiar_czasu, NULL); | |
} | |
void loop() { | |
t.update(); | |
} | |
void pomiar_czasu(void* p) { | |
sekundy++; | |
if (sekundy == 60) { | |
sekundy = 0; | |
minuty++; | |
if (minuty == 60) { | |
minuty = 0; | |
godziny++; | |
if (godziny == 24) { | |
godziny = 0; | |
} | |
} | |
} | |
} | |
void pokaz_czas(void* p) { | |
if (godziny < 10) { | |
Serial.print("0"); | |
Serial.print(godziny); | |
} else { | |
Serial.print(godziny); | |
} | |
Serial.print(":"); | |
if (minuty < 10) { | |
Serial.print("0"); | |
Serial.print(minuty); | |
} else { | |
Serial.print(minuty); | |
} | |
Serial.print(":"); | |
if (sekundy < 10) { | |
Serial.print("0"); | |
Serial.println(sekundy); | |
} else { | |
Serial.println(sekundy); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment