Skip to content

Instantly share code, notes, and snippets.

@MxBoud
Last active February 28, 2022 23:33
Show Gist options
  • Save MxBoud/2d7267fcb69d24c8a552390fb6eb9c38 to your computer and use it in GitHub Desktop.
Save MxBoud/2d7267fcb69d24c8a552390fb6eb9c38 to your computer and use it in GitHub Desktop.
Troubleshotting for BOB
//Modify feb 28/2022 MB
long lastTime = 0;
long seconds = 0;
String seconds_str = "00";
long minutes = 0;
String minutes_str = "00";
long hours = 0;
String hours_str = "00";
//#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() {
//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 ;
}
String time_string;
time_string = hours_str + ":"+minutes_str + ":" + seconds_str;
Serial.println(time_string);
}
//Merci
//POPA
//Cela fait plaisir!
//Maxime!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment