int btn_Status1 = 0;
int btn_Status2 = 0;
int mode = 0;
int timedif = 0;
int bklightstus = 1;
void setup()
{
pinMode(14, INPUT);
pinMode(12, INPUT);
}
void loop()
{
btn_Status1 = digitalRead(14);
btn_Status2 = digitalRead(12);
if (btn_Status1 == LOW){
if (mode == 3){
mode = 0;
}
else{
mode = mode + 1;
}
}
else
{
btn_Status1 = 0;
}
if (mode == 0){
time_t now = time(nullptr);
struct tm* p_tm = localtime(&now);
lcd.setCursor(0, 0);
lcd.write(3);
lcd.setCursor(1,0);
lcd.print("as");
lcd.setCursor(0, 1);
lcd.print(p_tm->tm_mday);
lcd.setCursor(2, 1);
lcd.print("/");
lcd.setCursor(3, 1);
lcd.print(p_tm->tm_mon + 1);
lcd.setCursor(5, 1);
lcd.print("/");
lcd.setCursor(6, 1);
lcd.print(p_tm->tm_year + 1900);
lcd.setCursor(11,1);
lcd.print(p_tm->tm_hour+timedif);
lcd.setCursor(13, 1);
lcd.print(":");
lcd.setCursor(14, 1);
lcd.print(p_tm->tm_min);
delay(1000);
lcd.clear();
}
else if (mode == 1){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("podsvietenie Z/V");
lcd.setCursor(0, 1);
lcd.print("Zap/Vyp");
if (btn_Status2 == LOW){
if (bklightstus == 1){
bklightstus = 0;
lcd.clear();
}
else{
bklightstus = 1;
lcd.clear();
}
}
else
{
}
if (bklightstus == 1){
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("podsvietenie:");
lcd.setCursor(0, 1);
lcd.print("Zapnute");
}
else{
lcd.setCursor(0, 0);
lcd.print("podsvietenie:");
lcd.noBacklight();
lcd.print("Vypnute");
lcd.clear();
}
delay(1000);
}
else if (mode == 2){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Mode 2");
delay(1000);
lcd.clear();
}
else{
delay(1000);
}
};
#Automatic loop error with arduino.
5 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
The code is meant to be that when button is pressed it changes the mode which will then change the functions being used. However when I press it it automatically changes the modes every 1 seconds due to the delays. it is not meant to change automatically only when button is pressed. I basically have no experience coding with C so im not sure where the error is 😦 .
Automatic loop error with arduino.
This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.