I have wrote a code in which an LED switches on after a button press and it will switch off after a given delay time but around a second before switching off i want it to blink as a warning that it is going to switch off, can you please help me modify the code given below in order for it to do this. Thank you for your help.
arduino12_5, your sketch is some kind of Finite State Machine: The Finite State Machine | Majenko Technologies.
If you are going to use that, then do it right as sherzaad showed.
When the behaviour of the buttons and the leds is the same, then it is possible to write just one Finite State Machine and use array's to do all the buttons and all the leds. Also the 'state' and the 'previousMillis' should be an array.
With a Finite State Machine you can add things and change things easy. If you want to blink and fade the leds or increase the blinking, all of that is possible. Example of millis() with Finite State Machine: millis_and_finite_state_machine.ino
gcjr, the leds blink only once ? You use 'On' and 'Off' for the buttons and the leds. That means the code is not suited when both the buttons and the leds are connected to GND.
arduino12_5, take a pick, we help you to make either of them work for you. I can think of a few more variations, but they are not better. There are libraries that would make this easier, but I prefer that you use millis() in its basic form to learn how millis() can be used best. Please always use 'unsigned long' when doing something with millis().
without being more precise, that's what interpreted blink to mean. did he mean blinking?
Koepel:
You use 'On' and 'Off' for the buttons and the leds. That means the code is not suited when both the buttons and the leds are connected to GND.
yes. i defined what On and Off mean for my case. instead of needing to replace the use of LOW/HIGH throughout the code for different hardware, there is just one place to change the enum values.
if the polarity of led and button are different, ButOn/ButOff and LedOn/LedOff make sense
i tried to show a simpler and cleaner approach for writing the code. i assume this is learning exercise for the OP and i think seeing well written code is the best way to learn to write well written code.