const int buttonPin = 2;
const int buzzerPin = 8;
void setup() {
pinMode (buttonPin, INPUT_PULLUP);
pinMode (buzzerPin, OUTPUT);
}
void loop() {
int buttonState = digitalRead(buttonPin);
if (buttonState == LOW) {
tone (buzzerPin, 1000);
} else {
noTone (buzzerPin);
}
}