// Pins
int button_pins[7] = {13, 12, 11, 10, 9, 8, 7};
int button_pins_length = sizeof(button_pins)/sizeof(button_pins[0]);
int buzzer_pin = 6;
int btn_value = 0;
// Notes
int pitch = 0;
int note_freqs[7] = {523, 587, 659, 698, 783, 880, 987};
void setup() {
// Set button pins
for (int i = 0; i < button_pins_length; i++){
pinMode(button_pins[i], INPUT_PULLUP);
}
// Set buzzer pin
pinMode(buzzer_pin, OUTPUT);
}
void loop() {
int note = 0;
// Check each button
for (int i = 0; i < button_pins_length; i++) {
btn_value = digitalRead(button_pins[i]);
if (btn_value == LOW) { // Button pressed
note = note_freqs[i]; // Set pitch to corresponding note frequency
}
}
if (note){
tone(buzzer_pin, note);
} else {
noTone(buzzer_pin);
}
}