How to exit while loop using keypad? I can't seem to be able to escape a while loop using a keypad button. I've tried the solution from this thread: https://forum.arduino.cc/index.php?topic=79932.0

Here's my code:

void alarm(){
  char customKey = customKeypad.getKey();

  while (customKey == NO_KEY){
    customKey = customKeypad.getKey();
    lcd.noDisplay();
    delay(750);// change for faster flash
    lcd.display();
    delay(750);// change for faster flash
  }
  lcd_home_screen();
}


I tried both == and != for the while (customKey == NO_KEY)

Additional info:
I am calling this alarm function from another function inside my Loop.
Here's the complete code:

void loop() {
  // keypad
  char customKey = customKeypad.getKey();    
  if (customKey == 'A'){
    main_program(5);
  }
}

int main_program(int duration){
  timer(duration);
  alarm();
}
Because you're using delay() within your while loop you have to ensure that you are pressing the key at the precise moment it is read.

You should not use delay().

Instead take a look at the BlinkWithoutDelay example in the IDE. And also consider implementing a Finite State Machine to know both if you're blinking and what state you're blinking currently is in.