Exit While loop if button pushed

Hi,
What I want to get is: if in next 5 sec user will not click the button, alarm will be activated.

I struggle with below code:

case 3:
 //deactivate


   time_now = millis();

  
  while (millis() < time_now + period) {
           //wait approx. 5 sec
     if (wylacz == LOW) {   //if button pushed
         stanAlarmu = 1;  //go to case deactivated

  }
stanAlarmu = 4;  // go to case lunch alarm
}
  break;

5sec wait is working, but why my IF in While does't break WHILE when pushed the button??

Thnx.

hum.. who do you think is updating wylacz magically for you in?    if (wylacz == LOW) {  //if button pushed

also if you don't want to have issues in ~50 days with millis() rolling over, you should write the test using subtraction not addition. Using magical numbers (1, 2, 3) for you alarm state is not great, use an enum it will be more readable.)

enum alarmState_t : byte {ALARM_IDLE, ALARM_ACTIVATED, ALARM_DEACTIVATED} stanAlarmu;
...
time_now = millis();
while (millis() - time_now < period) {
  if (digitalRead(myButton) == LOW) { // button pushed, cancel the wait period
    stanAlarmu = ALARM_DEACTIVATED;
    break;
  }
}
...

Last but not least, don't post snippets (Snippets R Us!)

J-M-L:
hum.. who do you think is updating wylacz magically for you in?    if (wylacz == LOW) {  //if button pushed

Thanks, it's interesting, when I changed it as per your suggestion it works - but why my variable "wylacz" doesn't work
wylacz == LOW

I have definied it as below:

#define rozbrojenie 6



int wylacz;

void setup() {
  // put your setup code here, to run once:


  pinMode(rozbrojenie, INPUT_PULLUP);

  
}

void loop() {
  // put your main code here, to run repeatedly:



wylacz = digitalRead(rozbrojenie);

I have definied it as below:

You give it a value but only once. In your code you do not give it a value in the while loop so it is not updated

Thanks you both!

that was my point when I wrote in post #1

hum.. who do you think is updating wylacz magically for you in?