#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
tone(buzzerPin, NOTE_C4); // Play C note when pressed
digitalWrite(buzzerPin, HIGH); // Turn on the buzzer
delay(250); // Keep the buzzer on for 0.25 seconds
noTone(buzzerPin); // Stop playing note
digitalWrite(buzzerPin, LOW); // Turn off the buzzer
buttonPressed = false; // Reset button state
noTone(buzzerPin); // Stop playing note
tone(buzzerPin, NOTE_D4); // Play D note when pressed
digitalWrite(buzzerPin, HIGH); // Turn on the buzzer
delay(250); // Keep the buzzer on for 0.25 seconds
noTone(buzzerPin); // Stop playing note
digitalWrite(buzzerPin, LOW); // Turn off the buzzer
tone(buzzerPin, NOTE_A4); // Play D note when pressed
digitalWrite(buzzerPin, HIGH); // Turn on the buzzer
delay(250); // Keep the buzzer on for 0.25 seconds
noTone(buzzerPin); // Stop playing note
digitalWrite(buzzerPin, LOW); // Turn off the buzzer
tone(buzzerPin, NOTE_A4); // Play D note when pressed
digitalWrite(buzzerPin, HIGH); // Turn on the buzzer
delay(250); // Keep the buzzer on for 0.25 seconds
noTone(buzzerPin); // Stop playing note
digitalWrite(buzzerPin, LOW); // Turn off the buzzer
tone(buzzerPin, NOTE_E2); // Play E note when pressed
digitalWrite(buzzerPin, HIGH); // Turn on the buzzer
delay(250); // Keep the buzzer on for 0.25 seconds
noTone(buzzerPin); // Stop playing note
}
}