Hallo Zusammen,
ich habe folgendes Problem:
ich möchte mit einem Taster ein Lauflicht mit Fastled an und ausschalten. Es soll auch immer mit der ersten LED beginnen.
Es hängt jetzt aber beim ausschalten. Das bekomme ich nicht hin.
Danke für eure Hilfe!
#include "FastLED.h"
//Data-pins: Ausgänge für die LED-Strips
#define DATA_PIN_1 2 // 1.Strip
#define DATA_PIN_2 3 // 2.Strip
#define DATA_PIN_3 4 // 3.Strip
#define DATA_PIN_4 5 // 4.Strip
#define DATA_PIN_5 6 // 5.Strip
#define LED_TYPE WS2811 //Chip-Typ des-LED Bandes
#define COLOR_ORDER GRB // "Color-Order" --> Farben Reihenfolge
//Helligkeit und Framerate festlegen
#define BRIGHTNESS 96
#define FRAMES_PER_SECOND 60
//Anzahl der Strips auf dem jeweiligen LED-Band
#define NUM_LEDS1 34
//Anzahl der Leds dem jeweiligen Band zuordnen
CRGB leds1[NUM_LEDS1];
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin0 = A0; // the number of the pushbutton pin
const int ledPin0 = 13; // the number of the LED pin
// Variables will change:
int ledState = HIGH; // the current state of the output pin
int buttonState; // the current reading from the input pin
int lastButtonState = LOW; // the previous reading from the input pin
// the following variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long lastDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 50; // the debounce time; increase if the output flickers
void setup() {
delay(3000);
pinMode(buttonPin0, INPUT);
pinMode(ledPin0, OUTPUT);
// set initial LED state
digitalWrite(ledPin0, ledState);
FastLED.addLeds<LED_TYPE,DATA_PIN_1,COLOR_ORDER>(leds1, NUM_LEDS1).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(BRIGHTNESS);
}
void loop() {
// read the state of the switch into a local variable:
int reading = digitalRead(buttonPin0);
// check to see if you just pressed the button
// (i.e. the input went from LOW to HIGH), and you've waited
// long enough since the last press to ignore any noise:
// If the switch changed, due to noise or pressing:
if (reading != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:
// if the button state has changed:
if (reading != buttonState) {
buttonState = reading;
// only toggle the LED if the new button state is HIGH
if (buttonState == HIGH) {
ledState = !ledState;
}
}
}
// set the LED:
digitalWrite(ledPin0, ledState);
if (ledState==HIGH){
FastLED.show();
FastLED.delay(1000/FRAMES_PER_SECOND);
fadeToBlackBy( leds1, NUM_LEDS1, 50);
int pos1 = beatsin16(20,0,NUM_LEDS1);
leds1[pos1] += CRGB( 255,0,0);}
if (ledState==LOW){
FastLED.clear ();
}
// save the reading. Next time through the loop,
// it'll be the lastButtonState:
lastButtonState = reading;
}