Arduino-Beispielcode (UNO R3)
// GoMaker × DFRobot — Papas Geburtstags-Box
// Hardware: DFRduino UNO R3 (DFR0011), LED-Kit (DFR0021), Buzzer (DFR0032), Taster (DFR0029)
// LEDs an Pins 3..10 | Buzzer: 11 | Button: 2 (GND, interner Pullup)
#include <Arduino.h>
const uint8_t LEDS[] = {3,4,5,6,7,8,9,10};
const uint8_t N = sizeof(LEDS);
const uint8_t PIN_BTN = 2;
const uint8_t PIN_BUZ = 11;
volatile bool startShow = false;
unsigned long lastPress = 0;
const unsigned long debounceMs = 180;
// ---- Noten (Hz) ----
#define C4 262
#define D4 294
#define E4 330
#define F4 349
#define G4 392
#define A4 440
#define B4 494
#define C5 523
#define D5 587
#define E5 659
#define F5 698
#define G5 784
// "Happy Birthday" (vereinfachte Fassung)
int melody[] = {
G4,G4,A4,G4,C5,B4,
G4,G4,A4,G4,D5,C5,
G4,G4,G5,E5,C5,B4,A4,
F5,F5,E5,C5,D5,C5
};
int dur[] = {
350,350,700,700,700,1200,
350,350,700,700,700,1200,
350,350,700,700,700,700,1200,
350,350,700,700,700,1200
};
// Herz-Animationen: Reihenfolge der LEDs (im Kreis/Herz)
const uint8_t order[] = {0,1,2,3,4,5,6,7};
void IRAM_ATTR onPress(){
unsigned long now = millis();
if (now - lastPress > debounceMs) {
startShow = true;
lastPress = now;
}
}
void allOff(){ for(uint8_t i=0;i127 ? HIGH : LOW);
}
delay(12);
}
for(int b=255;b>=0;b-=8){
for(uint8_t i=0;i127 ? HIGH : LOW);
}
delay(12);
}
}
for(uint8_t i=0;i
Nutzung: Ein kurzer Druck auf die Taste startet die Show: Intro-Funken → Lauflicht → Happy Birthday → Herz-Finale. Für „leise“ Feiern Buzzer abstecken – die Lichtshow funktioniert weiter.