#include "pitches.h"
const int buttonPin = 5;
const int buzzerPin = 8;
bool buttonPressed = false;
void setup() {
pinMode(buttonPin, INPUT_PULLUP);
pinMode(buzzerPin, OUTPUT);
}
void loop() {
if (digitalRead(buttonPin) == LOW) {
buttonPressed = true;
}
if (buttonPressed) {
noTone(buzzerPin); // Stop playing note
delay(2000); // Wait 2 seconds
tone(buzzerPin, NOTE_C4); // Play C note when pressed
digitalWrite(buzzerPin, HIGH); // Turn on the buzzer
delay(3000); // Keep the buzzer on for 3 seconds
noTone(buzzerPin); // Stop playing note
digitalWrite(buzzerPin, LOW); // Turn off the buzzer
buttonPressed = false; // Reset button state
}
}