const int buttonPins[] = {2, 3, 4, 5, 6, 7, 8}; // Pins for the push buttons
const int noteFrequencies[] = {262, 294, 330, 349, 392, 440, 494}; // Frequencies for C4 to B4
const int buzzerPin = 9; // Pin for the buzzer
void setup() {
for (int i = 0; i < 7; i++) {
pinMode(buttonPins[i], INPUT_PULLUP);
}
pinMode(buzzerPin, OUTPUT);
}
void loop() {
for (int i = 0; i < 7; i++) {
if (digitalRead(buttonPins[i]) == LOW) { // Button is pressed
tone(buzzerPin, noteFrequencies[i]); // Play the corresponding note
delay(300); // Change this delay to adjust note duration
noTone(buzzerPin); // Stop playing the note
delay(50); // Debounce delay
}
}
}