int x;
void setup() {
pinMode(2, INPUT); // Set pin 2 as input (pull-up)
pinMode(4, OUTPUT); // Set pin 4 as output
}
void loop() {
x = digitalRead(2); // Read the state of the push button
if (x == LOW) { // If the button is pressed
tone(4, 7000 , 250); // Play a 262Hz tone for 250 milliseconds
} else {
noTone(4); // Turn the buzzer off
}
}