// Definisikan pin untuk setiap tombol dan speaker
const int buttonDo = 1;
const int buttonRe = 2;
const int buttonMi = 3;
const int buttonFa = 4;
const int buttonSol = 5;
const int buttonLa = 6;
const int buttonSi = 7;
const int speakerPin = 0;
// Nada untuk setiap tombol (dalam Hz)
const int noteDo = 261; // C4
const int noteRe = 293; // D4
const int noteMi = 329; // E4
const int noteFa = 349; // F4
const int noteSol = 392; // G4
const int noteLa = 440; // A4
const int noteSi = 493; // B4
const int noteDoHigh = 523; // C5
void setup() {
// Setiap tombol sebagai input
pinMode(buttonDo, INPUT);
pinMode(buttonRe, INPUT);
pinMode(buttonMi, INPUT);
pinMode(buttonFa, INPUT);
pinMode(buttonSol, INPUT);
pinMode(buttonLa, INPUT);
pinMode(buttonSi, INPUT);
// Speaker sebagai output
pinMode(speakerPin, OUTPUT);
}
void loop() {
if (digitalRead(buttonDo) == HIGH) {
tone(speakerPin, noteDo);
} else if (digitalRead(buttonRe) == HIGH) {
tone(speakerPin, noteRe);
} else if (digitalRead(buttonMi) == HIGH) {
tone(speakerPin, noteMi);
} else if (digitalRead(buttonFa) == HIGH) {
tone(speakerPin, noteFa);
} else if (digitalRead(buttonSol) == HIGH) {
tone(speakerPin, noteSol);
} else if (digitalRead(buttonLa) == HIGH) {
tone(speakerPin, noteLa);
} else if (digitalRead(buttonSi) == HIGH) {
tone(speakerPin, noteSi);
} else {
noTone(speakerPin); // Matikan suara ketika tidak ada tombol yang ditekan
}
}