You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But you want also emit a sound with tone() while the LED is flashing.
These two actions can't be done at the same time, because the delay() function is blocking.
The program flashes the LED, stops, wait 500 ms and then emits the sound.
But you can do it at the same time !
The key is timing.
In Arduino, we can get the number of milliseconds since the power up of the board (millis ()function).
By declaring an interval and a timer in the loop, we can check if the interval has been exceeded since the last action. If this is the case, an action is executed. Otherwise, the program continues and rechecks each time. During this time the counter increments.
This library allows you to do this easily and quickly !