/*
MSJ Researchers World
Date - 21st OCT 2024
Mentor - Mr. Siranjeevi M
Contact - 7373771991
*/
// Pin assignments
const int buttonPin = 6; // Button connected to pin 6
const int buzzerPin = 9; // Buzzer connected to pin 9
// Variable to store the button state
int buttonState = 0;
void setup()
{
// Initialize the button pin as input
pinMode(buttonPin, INPUT);
}
void loop()
{
// Read the state of the button
buttonState = digitalRead(buttonPin);
// If the button is pressed, play a tone
if (buttonState == LOW)
{ // Button pressed (with pull-up)
tone(buzzerPin, 1000); // Generate a 1kHz tone
}
else
{
noTone(buzzerPin); // Stop the tone when the button is released
}
}