Iv'e bee bashing my head against a wall for sometime trying to work out the best way to write the code for a settings toggle button and was hoping someone could point me in the right direction.
I am using buttons on a touch screen and want one of the buttons to toggle between setting two alarms. I have done the code for the up & down buttons but need to toggle between;
#define Alarm0Hour 0
#define Alarm0Min 1
#define Alarm1Hour 2
#define Alarm1Min 3
#define ClearSelection 4
I thought a switch case would be the way to go but I'm not sure Im using the right approach. I have extracted out the relevant code.
What I'm trying to do is toggle between 5 states so when I press the UP buttons it will look to see which boolean is true & then do that.
Can anyone tell me whether I'm on the right track?
boolean Alarm0Hour_Set;
boolean Alarm0Minute_Set;
boolean Alarm1Hour_Set;
boolean Alarm1Minute_Set;
#define Alarm0Hour 0
#define Alarm0Min 1
#define Alarm1Hour 2
#define Alarm1Min 3
#define ClearSelection 4
else if (pressed_button == but11) { //Toggle within each setting
if (selectMode == true) {
settingsMillis = millis(); // Start being-in-select-mode timer
select++; // Move to next select option
myGLCD.setColor(255, 255, 0);
}
// switch (select % (MAXPARAM + 3))
switch (select) {
case Alarm0Hour:
Alarm0Hour_Set = true;
myGLCD.fillRect(218, 65, 16, 24); // Alarm0Hour
settingsMillis = millis(); // Start being-in-select-mode timer
break;
case Alarm0Min:
Alarm0Hour_Set = false;
Alarm0Minute_Set = true;
myGLCD.fillRect(266, 65, 12, 24); // Alarm0Min
myGLCD.print(":", 218, 65);
settingsMillis = millis(); // Start being-in-select-mode timer
break;
case Alarm1Hour:
Alarm0Minute_Set = false;
Alarm1Hour_Set = true;
myGLCD.fillRect(218, 102, 16, 24); // Alarm1Hour
myGLCD.print(":", 266, 65);
settingsMillis = millis(); // Start being-in-select-mode timer
break;
case Alarm1Min:
Alarm1Hour_Set = false;
Alarm1Minute_Set = true;
myGLCD.fillRect(266, 102, 12, 24); // Alarm1Min
myGLCD.print(":", 218, 102);
settingsMillis = millis(); // Start being-in-select-mode timer
break;
case ClearSelection:
Alarm1Minute_Set = false;
myGLCD.print(":", 266, 102);
settingsMillis = millis(); // Start being-in-select-mode timer
break;
}
}
}