Skip to content

Instantly share code, notes, and snippets.

@rafalw
Created March 20, 2019 12:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafalw/f7e178c7e97be393e26c74e8da7e59d4 to your computer and use it in GitHub Desktop.
Save rafalw/f7e178c7e97be393e26c74e8da7e59d4 to your computer and use it in GitHub Desktop.
Zegar czasu rzeczywistego – wersja 2. Konieczna modyfikacja!
#include <LiquidCrystal.h>
#include <Timer.h>
#define N 2
#define S 1000
Timer t;
int sekundy = 0;
int minuty = 0;
int godziny = 0;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
lcd.begin(16,2);
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) {
lcd.setCursor(0,0);
if (godziny < 10) {
lcd.print("0");
lcd.print(godziny);
} else {
lcd.print(godziny);
}
lcd.print(":");
if (minuty < 10) {
lcd.print("0");
lcd.print(minuty);
} else {
lcd.print(minuty);
}
lcd.print(":");
if (sekundy < 10) {
lcd.print("0");
lcd.print(sekundy);
} else {
lcd.print(sekundy);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment