Hello, I try to avoid delay because it cause Blynk to not run correctly, I Can’t figure out how to use simpleTimer to turn on buzzer for multiple different time.
for Example :
I have two buttons connected to D3 and D4 and buzzer to D2. and if D3 is pressed I want to beep buzzer for 3 time and if D4 is pressed I want to beep buzzer for 4 times and so on.
I tried use setTimer function with enable and disable TimerID but I can call setTimer ID only once time after pressed D3, or D4. need help!
It might be easier if we saw the script you are currently working with… but basicly it should be a simple matter of adjusting timeouts before turning off the buzzer… now pulsing the buzzer via timers then shutting it off is a bit more effort, but still doable.
I use this (possibly crude, but effective) code to latch a relay then flash an LED five (5) times, with 1 second pulses.
Read through it to see how it is done, then adapt it for your needs.
//===== LATCH (Relay) & LED PULSE - BLYNK Functions =====
BLYNK_WRITE(V40) // Virtual button on V40 to activate Relay_LED pulses
{
RLY_LED = param.asInt();
if (RLY_LED == 1 && Flag == 0){
Flag = 1; // Keeps from allowing button press more then once while relay activated
digitalWrite(30, HIGH); // Activate Relay
timer.setTimeout(2000L, Relay2OFF); // Deactivare Relay after 2 seconds
timer.setTimer(2000L, LedON, 5); // Pulse LED routine (LedON/LedOFF) 5 times
} // END if
} // END Blynk Function
void Relay2OFF()
{
digitalWrite(30, LOW);
Flag = 0; // reset flag after relay disables
} // END Relay2OFF Function
void LedON()
{
digitalWrite(31, HIGH); // Turn on LED
timer.setTimeout(1000L, LedOFF); // Run OFFLED routine once in 1 second
} // END LedON Function
void LedOFF()
{
digitalWrite(31, LOW); // Turn off LED
} // END LedOFF Function
thanks, you always helpful.