Can anyone help me make my code switch between ifs statements instantly?

This is a morse code that says hello with a buzzer and an LED.
When the button is pressed once it should switch instantly to only saying hello with the LED.
When its pressed again it should switch to just the buzzer. And if its press once more it should go back to being both. Im sure i made it much more complicated than it should be. It does switch but it has to run the entire loop before it switches. How do i make it switch instantly between ifs statements as soon as the button is pressed?

_3HelloToYou.ino (3.83 KB)

Set up a timer interrupt to check whether your button is down every few milliseconds. If it's down for a few consecutive milliseconds, consider it debounced. Then adjust your pin modes for Buzzer and LED accordingly. If either is set to INPUT, it'll basically be off. And then you can greatly reduce your code elsewhere to just always do both the LED and the buzzer and let the pin modes dictate which is heard/seen.

Get rid of all the delays in your code and it won't be a problem, plus you can remove all those calls to Check(). Even the fastest button press will last for tens of milliseconds. With the delays and unnecessary code removed your loop will only take a fraction of a millisecond.

See File > Examples > 02.Digital > BlinkWithoutDelay and the associated tutorial page:

for an example of how this is done.

There is no need for interrupts to detect humans pressing buttons. Humans are slow.

The demo Several Things at a Time is an extended example of BWoD and illustrates the use of millis() to manage timing. It may help with understanding the technique.

...R