Hello, I have searched the internet and am unable to find a solution to my problem. I am building a project and my background is more hardware than software,
I am using an OLED display, and my project is a lamp that has three modes, on, off, or a count down timer.
My loop looks something like this;
void loop()
{
if (toggle == 1) {
if (state == 0) {
lamp_on();
}
else if (state == 1){
lamp_timer();
}
else {
lamp_off();
}
}
toggle = 0;
}
The toggle variable is set by an interrupt on an input button, hence when the button is pressed it knows to jump to a sub routine. The correct subroutine is the next routine in sequence as set by the state variable at the end of the last sub routine.
My problem is, at the start of each subroutine a message is displayed on the OLED asking if the lamp wants to be turned on? /off? /timer? this should pause for a few seconds and then confirm this is the correct choice. However if the button is again pressed i need to jump immediately to the next sub routine, this will allow efficient control of the lamp with only one button. I am unable to advance as the interrupt does not return to the loop, and i cannot seem to use the millis() command outside of loop to check if the button has been pressed. Is there a way to pause the program while the message is displayed on the OLED but still check for a button press and if so cancel the current routine and jump to the next?
example of one of the routines:
void lamp_off(){
display.clearDisplay();
display.setCursor(0, 25);
display.println(F("LAMP:OFF?"));
display.display(); // Show initial text
delay(2000); // THIS IS WHERE THE CHECK NEEDS TO OCCUR
display.clearDisplay();
display.setCursor(0, 25);
display.println(F("LAMP:OFF!"));
display.display(); // Show initial text
display.invertDisplay(true);
delay(600);
display.clearDisplay();
display.setCursor(0, 25);
display.println(F("LAMP:OFF"));
display.display(); // Show initial text
display.invertDisplay(false);
digitalWrite(ledPin, LOW);
state = 0;
}
My programming is limited to old school BASIC, am i going about this the wrong way and the whole program should be inside loop to utilise millis()? any help appreciated