Hey all,
I'm new to Arduino coding and was hoping someone could suggest why my code isn't behaving as I had hoped.
Without going into verbose detail, there is an Uno with an LCD shield that has up/down/left/right buttons.
I can read the buttons fine, I can write to the screen fine, what is stumping me is how to change 'menus'. When I press my change menu button, it changes to the other menu (routine/function), then changes straight back.
Any help would be greatly appreciated!
-Dax.
The basic construction is this:
void loop()
{
setUVTimer();
}
// Functions //
void setUVTimer()
{
MB1 = analogRead (0);
if (MB1 < 60) { //change menu button
setTemperature();
}
else if (MB1 < 200) { //up button
uvtimer++;
if (uvtimer >15){uvtimer = 15;}
delay(250);
}
else if (MB1 < 400){ //down button
uvtimer--;
if (uvtimer <1){uvtimer = 1;}
delay(250);
}
lcd.print(uvtimer, DEC),lcd.print(" mins ");
}
void setTemperature()
{
lcd.print("Set temperature");
MB1 = analogRead (0);
if (MB1 < 60) { //change menu button
setUVTimer();
}
else if (MB1 < 200) { //up button
target_temp++;
if (target_temp >60){target_temp = 60;}
delay(180);
}
else if (MB1 < 400){ //down button
target_temp--;
if (target_temp <15){target_temp = 15;}
delay(180);
}
lcd.print(target_temp, DEC),lcd.print("\xDF""C ");
}
UPDATE: I realised an alternative solution was to put each of those subroutines inside for(::){} loops, since the subroutines all had exit points (to other subroutines) anyway.