-
Do not use delay(...) in your sketches.
delay(...) stops/blocks all code execution during the delay period. -
When you want a TIMER, use the millis( ) function as mentioned here:
-
Also, do not acted on switch levels, instead use changes in switch state.
-
Avoid using while( ) as it can block code execution.