Hallo zusammen
Ich bin ein wenig mit dem Arduino und einem LED-Band am basteln, dass es ein Lauflicht gibt.
Nun funktioniert dies eigentlich auch ganz gut jedoch kommt immer wieder blau mit ins Lauflicht und ich kann mir nicht erklären woher dies kommt. Ich habe blau eigentlich nirgends gewollt definiert. Kann mir da jemand weiterhelfen?
Danke.
#include <Bounce2.h>
#include <Adafruit_NeoPixel.h>
#define EINGANG_WEISS 12
#define EINGANG_VOR 11
#define EINGANG_ZURUCK 13
#define WEISS 75
int status = 0; //Zeigt den Status an => 0 = Aus // 1 = weiss // 2 = Vorwärts // 3 = Rückwärts
#define PIN 8
#define N_LEDS 50
Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_LEDS, PIN, NEO_RGBW + NEO_KHZ800);
Bounce entprellen1 = Bounce();
Bounce entprellen2 = Bounce();
Bounce entprellen3 = Bounce();
void setup()
{
pinMode(EINGANG_WEISS, INPUT_PULLUP); //Konfiguration Eingang weiss
entprellen1.attach(EINGANG_WEISS);
entprellen1.interval(100);
pinMode(EINGANG_VOR, INPUT_PULLUP); //Konfiguration Eingang Vorwärts
entprellen2.attach(EINGANG_VOR);
entprellen2.interval(100);
pinMode(EINGANG_ZURUCK, INPUT_PULLUP); //Konfiguration Eingang Zurück
entprellen3.attach(EINGANG_ZURUCK);
entprellen3.interval(100);
// this resets all the neopixels to an off state
strip.begin();
status = 0;
}
void loop()
{
taster_aktualisieren();
if (entprellen1.read() == LOW)
{
if(entprellen2.read() == HIGH && entprellen3.read() == HIGH)
{
status = 1; //Status auf weiss stellen
}
else
{
status = 4; //Status auf Error stellen
}
}
else if (entprellen2.read() == LOW)
{
if(entprellen1.read() == HIGH && entprellen3.read() == HIGH)
{
status = 2; //Status auf weiss stellen
}
else
{
status = 4; //Status auf Error stellen
}
}
else if (entprellen3.read() == LOW)
{
if(entprellen2.read() == HIGH && entprellen1.read() == HIGH)
{
status = 3; //Status auf weiss stellen
}
else
{
status = 4; //Status auf Error stellen
}
}
else
{
status = 0; //Status auf Aus stellen
}
switch (status) {
case 0:
for (int i = 0; i<= strip.numPixels(); i++)
{
strip.setPixelColor(i,0,0,0,0);
strip.show();
}
break;
case 1:
for (int i = 0; i<=strip.numPixels(); i++)
{
strip.setPixelColor(i,0,0,0,WEISS);
}
strip.show();
break;
case 2:
chaseVor(strip.Color(0, 255, 0,0)); // Green
break;
case 3:
chaseZur(strip.Color(0, 255, 0,0)); // Green
break;
case 4:
chaseBlink(strip.Color(255, 0, 0,0)); // Rot
break;
}
}
void taster_aktualisieren ()
{
entprellen1.update();
entprellen2.update();
entprellen3.update();
}
void chaseVor(uint32_t c) {
for(uint16_t r=0; r < 27; r++) {
strip.setPixelColor(r , c); //Pixel einschalten
strip.setPixelColor(r+27 , c); //Pixel einschalten
strip.setPixelColor(r-4, 0); //Pixel ausschalten
strip.setPixelColor(r+23 , 0); //Pixel ausschalten
strip.show();
delay(100);
}
}
void chaseZur(uint32_t c) {
for(int r = 22; r >= -4; r--) {
strip.setPixelColor(r , c); //Pixel einschalten
strip.setPixelColor(r+27 , c); //Pixel einschalten
strip.setPixelColor(r+4, 0); //Pixel ausschalten
strip.setPixelColor(r+31 , 0); //Pixel ausschalten
strip.show();
delay(100);
}
}
void chaseBlink(uint32_t c) {
for (int i = 0; i<= strip.numPixels(); i++)
{
strip.setPixelColor(i,c);
strip.show();
}
delay(500);
for (int i = 0; i<= strip.numPixels(); i++)
{
strip.setPixelColor(i,0,0,0,0);
strip.show();
}
delay(500);
}