int ledPins[] = {3, 4, 5, 7, 8, 9, 10, 11, 12, 13};
int ledCount = 10;
int buzzerPin = 6;
int melodyEpic[] = {147, 175, 196, 220, 247, 294, 330, 392, 440, 523};
void setup() {
for (int i = 0; i < ledCount; i++) {
pinMode(ledPins[i], OUTPUT);
}
pinMode(buzzerPin, OUTPUT);
}
void loop() {
ledakNaik();
delay(400);
gelombangMenyapu();
delay(400);
pulseCepat();
delay(400);
pinballMode();
delay(600);
}
void ledakNaik() {
for (int i = 0; i < ledCount / 2; i++) {
nyalakanLED(i);
nyalakanLED(ledCount - 1 - i);
tone(buzzerPin, melodyEpic[i] + (i * 30));
delay(100);
noTone(buzzerPin);
delay(20);
}
matikanSemuaLED();
}
void gelombangMenyapu() {
int durasi = 80;
for (int i = 0; i < ledCount; i++) {
matikanSemuaLED();
nyalakanLED(i);
if (i > 0) nyalakanLED(i - 1);
tone(buzzerPin, 440 - (i * 20));
delay(durasi);
noTone(buzzerPin);
}
for (int i = ledCount - 1; i >= 0; i--) {
matikanSemuaLED();
nyalakanLED(i);
if (i < ledCount - 1) nyalakanLED(i + 1);
tone(buzzerPin, 220 + (i * 15));
delay(durasi);
noTone(buzzerPin);
}
}
void pulseCepat() {
for (int j = 0; j < 5; j++) {
nyalakanSemuaLED();
if (j % 2 == 0) tone(buzzerPin, 600);
else tone(buzzerPin, 400);
delay(100);
matikanSemuaLED();
noTone(buzzerPin);
delay(100);
}
}
void pinballMode() {
for (int i = 0; i < 15; i++) {
int randomLed = random(0, ledCount);
matikanSemuaLED();
nyalakanLED(randomLed);
int freq = 300 + (randomLed * 40);
tone(buzzerPin, freq);
delay(80);
noTone(buzzerPin);
delay(40);
}
matikanSemuaLED();
}
void nyalakanLED(int index) {
if (index >= 0 && index < ledCount) digitalWrite(ledPins[index], HIGH);
}
void matikanSemuaLED() {
for (int i = 0; i < ledCount; i++) digitalWrite(ledPins[i], LOW);
}
void nyalakanSemuaLED() {
for (int i = 0; i < ledCount; i++) digitalWrite(ledPins[i], HIGH);
}