5 min delay loop exit when new button press in switch case

hello,

i m beginner in arduino and coding.. we are using switch case for particular event execution.. when we press switch (e.g. 3 number switch) that time loop executed but in this loop 5 min delay provide for toggling LED. ON led and after 5 min OFF.... my question is when start 5 min delay that time other switch press but not working... but after 5 min switch press then working..... how to exit when delay start and catch the new switch case number ..... please help mi..... how can i fix it ....

int light = 8;
static const uint32_t DELAY_1_S = 1000UL;
static const uint32_t DELAY_1_MINUTE = DELAY_1_S * 60UL;
static const uint32_t DELAY_1_HOUR = DELAY_1_MINUTE * 60UL;

case 2:
{

digitalWrite(light, HIGH);

delay(5UL * DELAY_1_MINUTE);

digitalWrite(light, LOW);

delay(5UL * DELAY_1_MINUTE);

}
break;

how exit when new switch press... help mi.......

Hello from the forum!
We really need to see more of your code to understand what is going on in other places.

You need to use a millis() timer. To understand millis() use there is a topic about it on the top if 'programming questions' section. And for using millis() is better rewrite thr prigram and don't try to fix it

//...
if (pushButtonThree == onState && timeOutFlag == 1) {
  switchCase = 3;
  timeOutFlag = 0;
  timeOutTimestamp = millis();
}
//...
if (millis() - timeOutTimestamp >= timeOutTime) {
  timeOutFlag = 1
}
//...

hello,

please help mi , i m confuse how to write source code .
when we press switch 7 then pwm generate and then press sw 2 for 4 min delay then loop start and execute delay that time no other instruction or function operate. becoz mcu busy in delay. we need to operate other switch case whenever key press but delay remains continuous running, only PWM changes that time .we use timer 1 for PWM generation... how to fix it please help mi .... give mi suggestion for it .

int PWM = 9;
int status[] = {0,0,0,0};

static const uint32_t DELAY_1_S = 1000UL;
static const uint32_t DELAY_1_MINUTE = DELAY_1_S * 60UL;
static const uint32_t DELAY_1_HOUR = DELAY_1_MINUTE * 60UL;

void setup()
{
Serial.begin(9600);
pinMode(PWM, OUTPUT);

}

void loop()
{
switch(results.value)
{ case sw5:

if(status[1] == 1)
{ ////Off the pwm

digitalWrite(PWM, LOW);
status[1] = 0;
}
else ////ON the pwm
{

digitalWrite(PWM, HIGH); // turn it on when the button is pressed
status[1] = 1; // and set its state as ON
TCCR1B = TCCR1B & ~ ((1 << CS12) | (1 << CS11) | (1 << CS10));
TCCR1A = (1 << COM1A1) | (0 << COM1A0)| (1 << COM1B1) | (1 <<
COM1B0) | (1 << WGM11) | (0 << WGM10);
TCCR1B = (0 << ICNC1) |(0 << ICES1)| (1 << WGM13) | (1 <<
WGM12)| (0 << CS12) | (0 << CS11) | (0 << CS10);
ICR1 = 48;
// OCR1A = 0;
TCCR1B = TCCR1B | (0 << CS12) | (1 << CS11) | (0 << CS10);

}
break;

case sw1:
if(status[1] == 1)
{

Serial.println("2 MIN TIMER ON%");
delay(2UL * DELAY_1_MINUTE); /// 2 MIN setting
digitalWrite(PWM, LOW);
}
break;
case sw2:
if(status[1] == 1)
{

delay(4UL * DELAY_1_MINUTE); /// FOR 4 MIN

digitalWrite(PWM, LOW);
}
break;
case sw3:
if(status[1] == 1)
{

delay(6UL * DELAY_1_MINUTE); /// FOR 6 MIN
digitalWrite(PWM, LOW);
}
break;
case sw4:
if(status[1] == 1)
{

delay(8UL * DELAY_1_MINUTE); /// FOR 8 MIN

digitalWrite(PWM, LOW);
}
break;
case sw6:
if(status[1] == 1)
{
OCR1A = 4;
}
break;
case sw7:
if(status[1] == 1)
{
OCR1A = 25;
}
break;
case sw8:
if(status[1] == 1)
{
OCR1A = 35;
}
break;
}
}

5 min or grater than that and other keys operates loop , its possible or Not in switch case loop. any other method to do, any idea or suggestion......

thanks,
Nilesh.

Make a table of what you want to do step by step and another of what the program does step by step. After modify your post by putting your code into code tags (see 'how to use this forum') and tell us if you have time limitations

Nilesh,

There's a handy-dandy link at the top of every forum page titled: Read this before posting a programming question ...

Despite this rather obvious title, you appear to have either not read the post or ignored the advice it contains. Please (re)read it now. Pay particular attention to Item #6 which tells you how to post your code using CODE TAGS so that it doesn't look so ugly and is easier for folks to read. Also, type 'ctrl-t' in the Arduino IDE to format you code with proper indentations.

Doing these things will make your posts and code much more readable. Remember, you're asking people on the forum to help you for FREE. The easier you make it for them, the more inclined they will be to do so. On the other hand, ignoring the well-documented forum guidelines displays a disrespect that will discourage people from helping you.