const int button1Pin = 34; // Pin untuk tombol pertama
const int button2Pin = 35; // Pin untuk tombol kedua
const int button3Pin = 32; // Pin untuk tombol ketiga
const int redPin = 2; // Pin untuk LED merah pada lampu RGB
const int greenPin = 4; // Pin untuk LED hijau pada lampu RGB
const int bluePin = 5; // Pin untuk LED biru pada lampu RGB
void setup() {
pinMode(button1Pin, INPUT);
pinMode(button2Pin, INPUT);
pinMode(button3Pin, INPUT);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop() {
if (digitalRead(button1Pin) == HIGH) {
playMelody1();
setRGB(255, 0, 0); // Merah
} else if (digitalRead(button2Pin) == HIGH) {
playMelody2();
setRGB(0, 255, 0); // Hijau
} else if (digitalRead(button3Pin) == HIGH) {
playMelody3();
setRGB(0, 0, 255); // Biru
} else {
noTone(18);
setRGB(0, 0, 0); // Matikan lampu jika tidak ada tombol yang ditekan
}
}
void playMelody1() {
// Kode melodi untuk tombol pertama
tone(18, 440, 500);
delay(1000);
noTone(18);
}
void playMelody2() {
// Kode melodi untuk tombol kedua
tone(18, 587, 500);
delay(2500);
noTone(18);
}
void playMelody3() {
// Kode melodi untuk tombol ketiga
tone(18, 659, 500);
delay(1700);
noTone(18);
}
void setRGB(int red, int green, int blue) {
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}
esp:0
esp:2
esp:4
esp:5
esp:12
esp:13
esp:14
esp:15
esp:16
esp:17
esp:18
esp:19
esp:21
esp:22
esp:23
esp:25
esp:26
esp:27
esp:32
esp:33
esp:34
esp:35
esp:3V3
esp:EN
esp:VP
esp:VN
esp:GND.1
esp:D2
esp:D3
esp:CMD
esp:5V
esp:GND.2
esp:TX
esp:RX
esp:GND.3
esp:D1
esp:D0
esp:CLK
btn1:1.l
btn1:2.l
btn1:1.r
btn1:2.r
btn2:1.l
btn2:2.l
btn2:1.r
btn2:2.r
btn3:1.l
btn3:2.l
btn3:1.r
btn3:2.r
rgb1:R
rgb1:COM
rgb1:G
rgb1:B
bz1:1
bz1:2