(Please understand that the sentence may sound unnatural using a translator.)
When I keep pressing Arduino's button, I want the buzzer to buzz once and the led to blink every 0.6 seconds.
But the code I wrote doesn't buzzed the buzzer. There may be many errors.
<
int btnPin = 2;
int ledPin = 13;
int btlPin = 4;
int bluePin = 12;
int buzzer = 3;
bool buzzerFlag = true;
Hello iris-002
Post your sketch, well formated, with comments and in so called code tags "</>" and schematic to see how we can help.
Have a nice day and enjoy coding in C++.
By this statement I assume the LED is blinking when you hold the button down. This means the buzzer is not working so you need to check your wiring. Write a simple program just to test the buzzer.
The tone() function gets called over and over again if buzzerFlag is true and btnState is HIGH. You never set buzzerFlag to false anywhere in your code.
What confuses me is that you have your button inputs set to INPUT_PULLUP so a "button pressed" condition is usually LOW for most applications. Are you using some kind of normally closed button?
Can you describe exactly what you want the program to do? I'm not sure I understand if you want the LEDs to blink WHILE you have the button pressed or in RESPONSE to a button press.
Hello iris-002
I´ve made a code review and the text editor has found five calls of the delay() function.
Line 21: tone(buzzer, 700, 2000); delay(150);
Line 23: delay(600);
Line 25: delay(500);
Line 34: delay(600);
Line 36: delay(500);
Each call will block the execution of the sketch for this time.
My proposal:
At least the sketch needs two timers to get the described functionality without call of delay().
Timer1: blinking Led
Timer2: timed buzzer
These timers are controlled by the bntPin and btlPin keys.
As base for these timers you can use the IDE example BlinkWithoutDelay as mother of all Adruino timers. Get started.
Have a nice day and enjoy coding in C++.