Created
February 28, 2022 23:35
-
-
Save MxBoud/82066d8bf4ba62257ec90f1f53cb7a5a to your computer and use it in GitHub Desktop.
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
//Modify feb 28/2022 MB | |
long lastTime = 0; | |
int seconds = 0; //Jamais plus grand que 60, donc on peut mettre un int | |
String seconds_str = "00"; | |
long minutes = 0; //Jamais plus grand que 60, donc on peut mettre un int | |
String minutes_str = "00"; | |
long hours = 0; //Jamais plus grand que 24, donc on peut mettre un int | |
String hours_str = "00"; | |
long last_update = -1; | |
//#include <LiquidCrystal_I2C.h> | |
//LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display | |
void setup() { | |
Serial.begin(9600); | |
//lcd.begin(16, 2); | |
//lcd.init(); // initialize the lcd | |
// lcd.backlight(); | |
} | |
void loop() { | |
update_time(); //Run the function update time defined below | |
if (seconds - last_update != 0) {//Only display the new time every second. | |
String time_string; | |
time_string = hours_str + ":" + minutes_str + ":" + seconds_str; | |
Serial.println(time_string); | |
last_update = seconds; | |
} | |
} | |
void update_time() { | |
//A chaque fois que tu avais plus grand que, j'ai changé pour plus grand ou égale que. Tu veux que la minut echange aussitôt que tu es | |
// a 60, et non pas quand que tu dépasse 60 | |
if (millis() - lastTime >= 1000 ) { //Modify from 1000 to 999 to get closer from clock time. | |
seconds++; | |
seconds_str = String(seconds); | |
if (seconds < 10) { | |
seconds_str = "0" + seconds_str; //Add a leading 0 | |
} | |
lastTime = millis(); | |
} | |
if (seconds >= 60) { | |
minutes++; | |
minutes_str = String(minutes); | |
if (minutes < 10) { | |
minutes_str = "0" + minutes_str; //Add a leading 0 | |
} | |
seconds = 0; | |
seconds_str = "0" + String(seconds); | |
} | |
if (minutes >= 60) { | |
hours++; | |
hours_str = String(hours); | |
if (hours < 10) { | |
hours_str = "0" + String(seconds); // Add a leading 0 | |
} | |
lastTime = millis(); | |
minutes = 0 ; | |
} | |
} | |
//Merci | |
//POPA | |
//Cela fait plaisir! | |
//Maxime! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment