//Pin Initialization
//Define the pin no for the push button
const int buttonPin = 9;
const int ledPin = 10 ;
const int buzzPin = 11;
// Define a variable to hold the current state of the button
int buttonState = LOW;
int buzzerState = LOW ;
int dt = 400 ;
int frq = 250;
void setup() {
//Start the serial monitor
Serial.begin(9600);
pinMode(buttonPin, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
pinMode(buzzPin, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
//Read the current state of the button(HIGH or LOW)
buttonState = digitalRead(buttonPin);
Serial.print(" Button = ");
Serial.println(buttonState);
//Check if the button1 is currently pressed(LOW)
if(buttonState == LOW){
buzzerState =!buzzerState;
digitalWrite(ledPin , buzzerState );// this is the synchronisation of led and buzzer state
if(buzzerState == HIGH){
tone(buzzPin , frq);
}else {
noTone(buzzPin);
}
delay(dt);
}
}
// push button 8,9
// led 10(pwm pin)
//buzzer 11
// if we use const then we can't change afterwards int he body too. it is reserved pin
// if we use #define then afterwards if we want we can change in the body.