#include <FastLED.h>
// How many LEDs in your strip?
#define NUM_LEDS 4
#define DATA_PIN 15
#define CLOCK_PIN 13
#define BUTTON_PIN_1 2 // Pin für Taster 1 (groß)
#define BUTTON_PIN_2 4 // Pin für Taster 2 (klein)
// Define the array of LEDs
CRGB leds[NUM_LEDS];
// Variablen für den Tasterzustand und die Entprellung
int lastButtonState1 = LOW;
int lastButtonState2 = LOW;
unsigned long lastDebounceTime1 = 0;
unsigned long lastDebounceTime2 = 0;
unsigned long debounceDelay = 100; // Erhöhte Entprellzeit
// Variable für die Farbstimmung
int colorMode = 0;
// Binärzähler
int binaryCounter = 0;
void setup() {
// Setze die Pins für die Taster als Eingänge mit internem Pull-up-Widerstand
pinMode(BUTTON_PIN_1, INPUT_PULLUP);
pinMode(BUTTON_PIN_2, INPUT_PULLUP);
// Setze die Pins für die LEDs als Ausgänge
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS); // GRB-Reihenfolge wird angenommen
// Setze die LEDs standardmäßig auf Rot
fill_solid(leds, NUM_LEDS, CRGB::Red);
FastLED.show();
}
void loop() {
// Lese die Tasterzustände mit Entprellung ein
int reading1 = digitalRead(BUTTON_PIN_1);
int reading2 = digitalRead(BUTTON_PIN_2);
unsigned long currentMillis = millis();
if (currentMillis - lastDebounceTime1 >= debounceDelay) {
if (reading1 != lastButtonState1) {
lastButtonState1 = reading1;
if (lastButtonState1 == HIGH) {
// Wechsele zwischen den Farbstimmungen
colorMode = (colorMode + 1) % 2;
// Setze die Farbe basierend auf der Farbstimmung
switch (colorMode) {
case 0: // Rot
fill_solid(leds, NUM_LEDS, CRGB(255, 0, 0));
break;
case 1: // Grün
fill_solid(leds, NUM_LEDS, CRGB(0, 128, 0));
break;
case 2: // Blau (funkioniert noch nicht)
fill_solid(leds, NUM_LEDS, CRGB(50, 38, 217));
break;
}
FastLED.show();
}
lastDebounceTime1 = currentMillis;
}
}
if (currentMillis - lastDebounceTime2 >= debounceDelay) {
if (reading2 != lastButtonState2) {
lastButtonState2 = reading2;
if (lastButtonState2 == HIGH) {
// Inkrementiere den binären Zähler
binaryCounter = (binaryCounter + 1) % 16;
// Setze die LEDs entsprechend dem binären Zähler
for (int i = 0; i < NUM_LEDS; i++) {
if (binaryCounter & (1 << i)) {
leds[i] = CRGB::White; // LED einschalten
} else {
leds[i] = CRGB::Black; // LED ausschalten
}
}
FastLED.show();
}
lastDebounceTime2 = currentMillis;
}
}
}