# Arduino und Ws2812 nach Durchgang alles leds aus schalten

**URL:** <https://forum.arduino.cc/t/arduino-und-ws2812-nach-durchgang-alles-leds-aus-schalten/1369353>\
**Category:** Deutsch\
**Created:** [April 1, 2025, 4:52am UTC](https://forum.arduino.cc/t/arduino-und-ws2812-nach-durchgang-alles-leds-aus-schalten/1369353 "2025-04-01T04:52:40Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![brain2412](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/brain2412/32/1127186_2.png) [@brain2412](https://forum.arduino.cc/u/brain2412)\
**Post date:** [April 1, 2025, 4:52am UTC](https://forum.arduino.cc/t/arduino-und-ws2812-nach-durchgang-alles-leds-aus-schalten/1369353/1 "2025-04-01T04:52:40Z")

</div>

Hallo ich bin neue hier und auch in der ganzen Arduino sache.

Ich benutze ein Arduino nano  
dazu AZDelivery IR Infrarot Modul  
und ein ws2812 led streifen  
oder zum ersten code halt Normale led s

also ich habe eine Kugelbahn und möchte das einige Led´s leuchten oder blinken wenn die Kugel vorbei läuft, bei den Normalen Led´s funktioniert das auch ich benutze ein ir Sensor wenn sie vorbei kommt gehen die einzelnen led s an und wieder aus, aber bei dem led Stripe WS2812 bekomme ich das nur so hin das er immer wieder von vorn anfängt und nicht sage ich mal nach der 11 ausgeht, und das z.b. jede 2 led ne andere Farbe hat.  
bei den normalen Led s habe ich folgenden code benutzt

```arduino
//int IRSensor1 = 1; 
int IRSensor2 = 2;

void setup() 
{
   pinMode (IRSensor2, INPUT);
  pinMode (6, OUTPUT); 
  pinMode (7, OUTPUT);
  pinMode (8, OUTPUT);
  pinMode (9, OUTPUT);
  pinMode (10, OUTPUT);
  pinMode (11, OUTPUT);
  pinMode (12, OUTPUT);
  pinMode (13, OUTPUT);
}

void loop()
{
  int statusSensor1 = digitalRead (IRSensor1);
  int statusSensor2 = digitalRead (IRSensor2);

  if (statusSensor2 == 0)
  {
     digitalWrite(13, HIGH);
    delay(50);
     digitalWrite(12, HIGH);
    delay(50);
     digitalWrite(11, HIGH);
    delay(50);
     digitalWrite(10, HIGH);
    delay(50);
     digitalWrite(9, HIGH);
    delay(50);
     digitalWrite(8, HIGH);
    delay(50);
     digitalWrite(7, HIGH);
    delay(50);
     digitalWrite(6, HIGH);
    delay(20);
     digitalWrite(13, LOW);
    delay(50);
     digitalWrite(12, LOW);
    delay(50);
     digitalWrite(11, LOW);
    delay(500);
     digitalWrite(10, LOW);
    delay(50);
     digitalWrite(9, LOW);
    delay(50);
     digitalWrite(8, LOW);
    delay(500);
     digitalWrite(7, LOW);
    delay(50);
     digitalWrite(6, LOW);
  }
  else
  {
     digitalWrite(13, LOW);
     digitalWrite(12, LOW);
     digitalWrite(11, LOW);
     digitalWrite(10, LOW);
     digitalWrite(9, LOW);
     digitalWrite(8, LOW);
     digitalWrite(7, LOW);
     digitalWrite(6, LOW);
  }  
}

```

und bei dem led streifen habe ich den code aus dem Beispiel  
benutzt ersmal ohne ir sensor um zu schauen wie das funktoniert

```arduino
 #include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#endif
#define PIN 6 
#define NUMPIXELS 11 

Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 500 
void setup() {
  pixels.begin(); 
}
void loop() {
    pixels.clear();
    for(int i=0; i<NUMPIXELS; i++) {  
    pixels.setPixelColor(i, pixels.Color(0, 150, 0));
    delay(100);
    pixels.show();   
    delay(DELAYVAL);
    
  }
}

```

aber ich weiß auch nicht warum die erste Led im streifen immer an bleibt und er immer neu anfängt gibt es da nicht auch so eine code wie digitalwrite wie ich das beim ersten code gemacht habe ??  
Ich hoffe ihr steigt hier durch  
viele grüße Benjamin

---

<div class="post-metadata">

**Author:** ![noiasca](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/noiasca/32/1126910_2.png) [@noiasca](https://forum.arduino.cc/u/noiasca)\
**Post date:** [April 1, 2025, 5:19am UTC](https://forum.arduino.cc/t/arduino-und-ws2812-nach-durchgang-alles-leds-aus-schalten/1369353/2 "2025-04-01T05:19:48Z")

</div>

lies zunächst diese Forumsanleitung:

> [@Wie man dieses Forum benutzt - bitte lesen](https://forum.arduino.cc/t/wie-man-dieses-forum-benutzt-bitte-lesen/902274):
>
> Bitte lies die Hinweise zur Benutzung dieses Forums, um Tipps zum Verfassen von Forumsbeiträgen zu erhalten und dieses Forum optimal zu nutzen. Vielen Dank! Das Arduino Forum Team . Dies ist eine Übersetzung von [How to get the best from this forum](https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum/679966) von [Perry Bebbinton](https://forum.arduino.cc/u/PerryBebbington). Hallo, Willkommen im Arduino Forum. Dieser Leitfaden erklärt, wie Sie dieses Forum am besten nutzen können. Bitte lesen und befolgen Sie die folgenden Anweisungen. Wenn Sie neu hier sin…

und dann korrigiere deinen ersten Post und poste deine Codes in Code Tags.

---

<div class="post-metadata">

**Author:** ![hawe07546](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hawe07546/32/1013044_2.png) [@hawe07546](https://forum.arduino.cc/u/hawe07546)\
**Post date:** [April 1, 2025, 7:57am UTC](https://forum.arduino.cc/t/arduino-und-ws2812-nach-durchgang-alles-leds-aus-schalten/1369353/3 "2025-04-01T07:57:39Z")

</div>

> [@brain2412](#):
>
> .... und er immer neu anfängt

Versteh ich nicht, Du durchläufst doch ständig die _loop_, logisch das sich alles wiederholt???

> [@brain2412](#):
>
> ich weiß auch nicht warum die erste Led im streifen immer an bleibt

Macht sie nicht, Du guckst nur zu langsam .... 😂  
Bin mir jetzt nicht sicher, ist eine Weile her mit den LED.  
Weil Du am Anfang der _loop_ zwar alle LED löschst, aber auch anschließend LED 0 setzt und **dann erst** die Befehle ausführen lässt-\> pixels.show().

cu

---

<div class="post-metadata">

**Author:** ![derGeppi](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dergeppi/32/249283_2.png) [@derGeppi](https://forum.arduino.cc/u/derGeppi)\
**Post date:** [April 1, 2025, 8:01am UTC](https://forum.arduino.cc/t/arduino-und-ws2812-nach-durchgang-alles-leds-aus-schalten/1369353/4 "2025-04-01T08:01:22Z")

</div>

> [@brain2412](#):
>
> aber ich weiß auch nicht warum die erste Led im streifen immer an bleibt

Erstmal willkommen hier im Forum und danke für das nachträgliche lesbar machen der geposteten sketches 😄  
Die erste LED bleibt immer an, weil sie in jedem loop-Durchlauf immer als erstes angeschaltet wird und `pixels.clear();` ohne ein `pixels.show();` die gelöschten Daten (alle LEDs aus) nicht an deine LEDs übermittelt.  
Tipp: das pixels.clear und .show NACH der FOR-Schleife ausführen.

> [@brain2412](#):
>
> ..und er immer neu anfängt

im ersten sketch hast du das Lauflicht an eine Bedingung (statussensor == 2) geknüpft und es wird nur dann ausgeführt.  
Im zweiten Sketch fehlt diese und blinkt daher bei jedem Loop-Durchlauf.

---

<div class="post-metadata">

**Author:** ![agmue](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/agmue/32/750067_2.png) [@agmue](https://forum.arduino.cc/u/agmue)\
**Post date:** [April 1, 2025, 11:02am UTC](https://forum.arduino.cc/t/arduino-und-ws2812-nach-durchgang-alles-leds-aus-schalten/1369353/5 "2025-04-01T11:02:23Z")

</div>

> [@brain2412](#):
>
> IR Infrarot Modul

Wird von `delay` blockiert und macht den Arduino "blind". Daher solltest Du `delay` meiden.

> [@brain2412](#):
>
> `for(int i=0; i<NUMPIXELS; i++)`

Du hast mit `loop` schon eine Schleife, da benötigst Du `for` nicht zusätzlich.

Eine Schrittkette, wenn hier auch nur mit zwei Schritten, erleichtert das Verständnis des Ablaufs.

> **Programm als Anregung**
>
> ```arduino
> #include <Adafruit_NeoPixel.h>
> #define PIN 6
> #define NUMPIXELS 11
> Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
> 
> const byte IRSensor2 = 2;
> const uint32_t intervall = 500;
> uint32_t jetzt, vorhin;
> byte schritt = 0;
> byte pix = 0;
> 
> void setup() {
> Serial.begin(115200);
> Serial.println("\nStart");
> pinMode (IRSensor2, INPUT_PULLUP);
> pixels.begin();
> }
> 
> void loop() {
> jetzt = millis();
> 
> switch (schritt) {
> case 0:
> if ( !digitalRead (IRSensor2) ) {
> vorhin = jetzt;
> pixels.setPixelColor(pix, pixels.Color(0, 150, 0));
> pixels.show();
> schritt++;
> }
> break;
> case 1:
> if (jetzt - vorhin >= intervall) {
> vorhin = jetzt;
> if (pix < NUMPIXELS) {
> pix++;
> pixels.setPixelColor(pix, pixels.Color(0, 150, 0));
> pixels.show();
> } else {
> pixels.clear();
> pixels.show();
> pix = 0;
> schritt = 0;
> }
> }
> break;
> }
> }
> 
> ```

Wenn der Eingang auf GND geschaltet wird - ein IR macht das vermutlich umgekehrt - leuchten nacheinander elf Pixel auf, um dann wieder zu verlöschen.

Hilft Dir das?

---

<div class="post-metadata">

**Author:** ![brain2412](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/brain2412/32/1127186_2.png) [@brain2412](https://forum.arduino.cc/u/brain2412)\
**Post date:** [April 1, 2025, 5:27pm UTC](https://forum.arduino.cc/t/arduino-und-ws2812-nach-durchgang-alles-leds-aus-schalten/1369353/6 "2025-04-01T17:27:31Z")

</div>

Hallo  
Ja danke  
Ich werde Heute Abend mal weiter Probieren  
und werde morgen berichten wie weit ich gekommen bin  
Danke schon einmal für eure freundliche Hilfe

---

<div class="post-metadata">

**Author:** ![brain2412](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/brain2412/32/1127186_2.png) [@brain2412](https://forum.arduino.cc/u/brain2412)\
**Post date:** [April 2, 2025, 5:01am UTC](https://forum.arduino.cc/t/arduino-und-ws2812-nach-durchgang-alles-leds-aus-schalten/1369353/7 "2025-04-02T05:01:04Z")

</div>

So Ich noch einmal das Programm zur Anregung hat mir sehr weiter geholfen dazu nochmals vielen Dank. 🙂  
wenn ich jetzt z.b 2 led s blau haben will 3 bleiben immer aus und 1 wieder weiß egal halt muss ich jetzt dem Programm sagen das wie hier im Beispiel jede einzelne Led einen Namen geben z.b.

```arduino
byte pix = 0;
byte pix = 1;
byte pix = 2;
byte pix = 3;
die Farben sind ja erstmal egal
pixels.setPixelColor(0, pixels.Color(255, 255, 255));
pixels.setPixelColor(1, pixels.Color(0, 0, 0));
pixels.setPixelColor(2, pixels.Color(0, 0, 255));
pixels.setPixelColor(3, pixels.Color(0, 0, 127));

```

währe das so richtig?

---

<div class="post-metadata">

**Author:** ![wwerner](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/wwerner/32/1001727_2.png) [@wwerner](https://forum.arduino.cc/u/wwerner)\
**Post date:** [April 2, 2025, 5:20am UTC](https://forum.arduino.cc/t/arduino-und-ws2812-nach-durchgang-alles-leds-aus-schalten/1369353/8 "2025-04-02T05:20:40Z")

</div>

> [@brain2412](#):
>
> ```arduino
> byte pix = 0;
> byte pix = 1;
> byte pix = 2;
> byte pix = 3;
> 
> ```

Das wird der Compiler nicht mögen. Gleiche Variable mehrfach genutzt. Zudem ganz schlechte Namen: Benutze Namen wie dieErsteLEDImStripe. Dann weißt du morgen auch noch was damit gemeint ist.

---

<div class="post-metadata">

**Author:** ![noiasca](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/noiasca/32/1126910_2.png) [@noiasca](https://forum.arduino.cc/u/noiasca)\
**Post date:** [April 2, 2025, 5:36am UTC](https://forum.arduino.cc/t/arduino-und-ws2812-nach-durchgang-alles-leds-aus-schalten/1369353/9 "2025-04-02T05:36:12Z")

</div>

> [@brain2412](#):
>
> wenn ich jetzt z.b 2 led s blau haben will 3 bleiben immer aus und 1 wieder weiß egal halt muss ich jetzt dem Programm sagen das wie hier im Beispiel jede einzelne Led einen Namen geben

wenn die Pixel eine besondere Bedeutung haben dann gib ihnen einen Namen.  
Z.B. Auf einem Modellauto  
blinkerLinks  
blinkerRechts  
scheinwerferLinks  
scheinwerferRechts  
rundumleuchteOben  
ruecklichtLinks  
usw

Wenn das nur in einem langen Strip ist und du die Pixel per Nummer ansprechen willst, dann belass es auf der Nummerierung - und achte eben darauf, dass man mit 0 zum zählen beginnt.

Wenn du mehrere Abschnitte auf deiner Bahn hast und für jeden Abschnitt eine andere Animation hast, dann könntest den ersten Pixel jedes Abschnitts einen Namen geben.

Wenn du Farben öfters wiederverwenden willst, dann leg dir ein paar Konstanten an (weiss, rot, gruen,...)

---

<div class="post-metadata">

**Author:** ![agmue](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/agmue/32/750067_2.png) [@agmue](https://forum.arduino.cc/u/agmue)\
**Post date:** [April 2, 2025, 10:26am UTC](https://forum.arduino.cc/t/arduino-und-ws2812-nach-durchgang-alles-leds-aus-schalten/1369353/10 "2025-04-02T10:26:14Z")

</div>

Wenn Du den Abschnitten individuelle Farben zuordnen möchtest, kannst Du auch eine Struktur verwenden:

> **Programm mit Struktur**
>
> ```arduino
> #include <Adafruit_NeoPixel.h>
> #define PIN 6
> #define NUMPIXELS 11
> Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
> 
> struct Animation {
> const byte p;
> const byte r, g, b;
> void ein() {
> pixels.setPixelColor(p, pixels.Color(r, g, b));
> }
> };
> Animation animation[NUMPIXELS] {
> //p r g b
> { 0, 50, 50, 50},
> { 1, 50, 0, 0},
> { 2, 0, 50, 0},
> { 3, 0, 0, 50},
> { 4, 25, 50, 25},
> { 5, 50, 50, 0},
> { 6, 50, 0, 50},
> { 7, 0, 50, 50},
> { 8, 138, 43, 226},
> { 9, 165, 42, 42},
> {10, 0, 255, 0},
> };
> const byte IRSensor2 = 2;
> const uint32_t intervall = 500;
> uint32_t jetzt, vorhin;
> byte schritt = 0;
> byte pix = 0;
> 
> void setup() {
> Serial.begin(115200);
> Serial.println("\nStart");
> pinMode (IRSensor2, INPUT_PULLUP);
> pixels.begin();
> }
> 
> void loop() {
> jetzt = millis();
> 
> switch (schritt) {
> case 0:
> if ( !digitalRead (IRSensor2) ) {
> schritt++;
> }
> break;
> case 1:
> if (jetzt - vorhin >= intervall) {
> vorhin = jetzt;
> if (pix < NUMPIXELS) {
> animation[pix].ein();
> pix++;
> pixels.show();
> } else {
> pixels.clear();
> pixels.show();
> pix = 0;
> schritt = 0;
> }
> }
> break;
> }
> }
> 
> ```

---

<div class="post-metadata">

**Author:** ![brain2412](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/brain2412/32/1127186_2.png) [@brain2412](https://forum.arduino.cc/u/brain2412)\
**Post date:** [April 3, 2025, 11:38am UTC](https://forum.arduino.cc/t/arduino-und-ws2812-nach-durchgang-alles-leds-aus-schalten/1369353/11 "2025-04-03T11:38:27Z")

</div>

Hey wow  
das ist ja Super jetzt verstehe ich das auch (glaube ich...)

SUPER echt vielen vielen Lieben Dank 🙂

noch eine frage kann man per software die die Entfernung auch einstellen?  
beim Ir sensor drehe ich die kleine Schraube aber er geht schon los obwohl keine Bewegung da ist nur kurz vorm ende geht das und da erkennt er es manchmal nicht oder liegt das an der Helligkeit oder muss ich da was abkleben zur zeit liegt er einfach auf dem Tisch  
nochmals vielen Lieben Dank

---

<div class="post-metadata">

**Author:** ![agmue](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/agmue/32/750067_2.png) [@agmue](https://forum.arduino.cc/u/agmue)\
**Post date:** [April 3, 2025, 1:37pm UTC](https://forum.arduino.cc/t/arduino-und-ws2812-nach-durchgang-alles-leds-aus-schalten/1369353/12 "2025-04-03T13:37:23Z")

</div>

> [@brain2412](#):
>
> jetzt verstehe ich das auch

Das wäre schön 🙂

> [@brain2412](#):
>
> per software die die Entfernung auch einstellen?

Ein entsprechender IR-Sensor ist mir nicht bekannt.

Bei Ultraschall und [LIDAR](https://www.adafruit.com/product/3967) geht das.

---

<div class="post-metadata">

**Author:** ![brain2412](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/brain2412/32/1127186_2.png) [@brain2412](https://forum.arduino.cc/u/brain2412)\
**Post date:** [April 16, 2025, 8:15pm UTC](https://forum.arduino.cc/t/arduino-und-ws2812-nach-durchgang-alles-leds-aus-schalten/1369353/13 "2025-04-16T20:15:04Z")

</div>

Hallo  
wie bekomme ich das ganze noch einmal hin  
also mit noch einem Sensor und noch ein stück led streifen  
und auch wo ich die einzelnen Led s ansteuern kann ich habe das mal so versucht

```arduino
#include <Adafruit_NeoPixel.h>
#define PIN 6
#define NUMPIXELS 11
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

struct Animation {
  const byte p;
  const byte r, g, b;
  void ein() {
    pixels.setPixelColor(p, pixels.Color(r, g, b));
  }
};
Animation animation[NUMPIXELS] {
  //p r g b
  { 0, 50, 50, 50},
  { 1, 50, 0, 0},
  { 2, 0, 0, 0},
  { 3, 0, 0, 50},
  { 4, 25, 50, 25},
  { 5, 50, 50, 0},
  { 6, 50, 0, 50},
  { 7, 0, 50, 50},
  { 8, 138, 43, 226},
  { 9, 165, 42, 42},
  {10, 0, 255, 0},
};
const byte IRSensor2 = 2;
const uint32_t intervall = 100;
uint32_t jetzt, vorhin;
byte schritt = 0;
byte pix = 0;

#define PIN 7
#define NUMPIXELS 5
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

struct Animation {
  const byte p;
  const byte r, g, b;
  void ein() {
    pixels.setPixelColor(p, pixels.Color(r, g, b));
  }
};
Animation animation[NUMPIXELS] {
  //p r g b
  { 0, 50, 90, 50},
  { 1, 255, 25, 255},
  { 2, 0, 0, 0},
  { 3, 255, 255, 50},
  { 4, 0, 50, 25},
 
};
const byte IRSensor3 = 3;
const uint32_t intervall = 100;
uint32_t jetzt, vorhin;
byte schritt = 0;
byte pix = 0;

void setup() {
  Serial.begin(115200);
  Serial.println("\nStart");
  pinMode (IRSensor2, INPUT_PULLUP);
  pixels.begin();
}

void loop() {
  jetzt = millis();

  switch (schritt) {
    case 0:
      if ( !digitalRead (IRSensor2) ) {
        schritt++;
      }
      break;
    case 1:
      if (jetzt - vorhin >= intervall) {
        vorhin = jetzt;
        if (pix < NUMPIXELS) {
          animation[pix].ein();
          pix++;
          pixels.show();
        } else {
          pixels.clear();
          pixels.show();
          pix = 0;
          schritt = 0;
        }
      }
      break;
      {
  jetzt = millis();

  switch (schritt) {
    case 0:
      if ( !digitalRead (IRSensor3) ) {
        schritt++;
      }
      break;
    case 1:
      if (jetzt - vorhin >= intervall) {
        vorhin = jetzt;
        if (pix < NUMPIXELS) {
          animation[pix].ein();
          pix++;
          pixels.show();
        } else {
          pixels.clear();
          pixels.show();
          pix = 0;
          schritt = 0;
        }
      }
      break;
  }
}

```

das war so meine idee wie man das machen könnte  
aber das Funktioniert nicht

---

<div class="post-metadata">

**Author:** ![agmue](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/agmue/32/750067_2.png) [@agmue](https://forum.arduino.cc/u/agmue)\
**Post date:** [April 17, 2025, 5:50pm UTC](https://forum.arduino.cc/t/arduino-und-ws2812-nach-durchgang-alles-leds-aus-schalten/1369353/14 "2025-04-17T17:50:29Z")

</div>

> [@brain2412](#):
>
> wie bekomme ich das ganze noch einmal hin

Verdoppeln ist möglich, aber Konstanten und Variablen müssen eindeutig benannt sein. Ich habe das mal mit "\_A" und "\_B" so gemacht:

> **Programm für zwei Bewegungssensoren**
>
> ```arduino
> #include <Adafruit_NeoPixel.h>
> #define PIN_A 22// 6
> #define NUMPIXELS_A 11
> Adafruit_NeoPixel pixels_A(NUMPIXELS_A, PIN_A, NEO_GRB + NEO_KHZ800);
> 
> #define PIN_B 23// 7
> #define NUMPIXELS_B 5
> Adafruit_NeoPixel pixels_B(NUMPIXELS_B, PIN_B, NEO_GRB + NEO_KHZ800);
> 
> struct Animation {
> const byte p;
> const byte r, g, b;
> void ein(Adafruit_NeoPixel &pixels) {
> pixels.setPixelColor(p, pixels.Color(r, g, b));
> }
> };
> Animation animation_A[NUMPIXELS_A] {
> //p r g b
> { 0, 50, 50, 50},
> { 1, 50, 0, 0},
> { 2, 0, 0, 0},
> { 3, 0, 0, 50},
> { 4, 25, 50, 25},
> { 5, 50, 50, 0},
> { 6, 50, 0, 50},
> { 7, 0, 50, 50},
> { 8, 138, 43, 226},
> { 9, 165, 42, 42},
> {10, 0, 255, 0},
> };
> 
> Animation animation_B[NUMPIXELS_B] {
> //p r g b
> { 0, 50, 90, 50},
> { 1, 255, 25, 255},
> { 2, 0, 0, 0},
> { 3, 255, 255, 50},
> { 4, 0, 50, 25},
> };
> 
> uint32_t jetzt;
> 
> const byte IRSensor_A = 12;
> const uint32_t intervall_A = 100;
> uint32_t vorhin_A;
> byte schritt_A = 0;
> byte pix_A = 0;
> 
> const byte IRSensor_B = 13;
> const uint32_t intervall_B = 100;
> uint32_t vorhin_B;
> byte schritt_B = 0;
> byte pix_B = 0;
> 
> void setup() {
> Serial.begin(115200);
> Serial.println("\nStart");
> pinMode (IRSensor_A, INPUT_PULLUP);
> pinMode (IRSensor_B, INPUT_PULLUP);
> pixels_A.begin();
> pixels_B.begin();
> }
> 
> void loop() {
> schrittkette_A();
> schrittkette_B();
> }
> 
> void schrittkette_A() {
> jetzt = millis();
> 
> switch (schritt_A) {
> case 0:
> if ( !digitalRead (IRSensor_A) ) {
> schritt_A++;
> }
> break;
> case 1:
> if (jetzt - vorhin_A >= intervall_A) {
> vorhin_A = jetzt;
> if (pix_A < NUMPIXELS_A) {
> animation_A[pix_A].ein(pixels_A);
> pix_A++;
> pixels_A.show();
> } else {
> pixels_A.clear();
> pixels_A.show();
> pix_A = 0;
> schritt_A = 0;
> }
> }
> break;
> }
> }
> 
> void schrittkette_B() {
> jetzt = millis();
> 
> switch (schritt_B) {
> case 0:
> if ( !digitalRead (IRSensor_B) ) {
> schritt_B++;
> }
> break;
> case 1:
> if (jetzt - vorhin_B >= intervall_B) {
> vorhin_B = jetzt;
> if (pix_B < NUMPIXELS_B) {
> animation_B[pix_B].ein(pixels_B);
> pix_B++;
> pixels_B.show();
> } else {
> pixels_B.clear();
> pixels_B.show();
> pix_B = 0;
> schritt_B = 0;
> }
> }
> break;
> }
> }
> 
> ```

Das ist keine hohe Kunst des Programmierens, sondern soll nur versuchen, Deinem Gedankengang zu folgen. Man könnte beispeilsweise beide Funktionen zusammenfassen und anstelle einzelner Variablen Felder verwenden 🙂

---

<div class="post-metadata">

**Author:** ![brain2412](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/brain2412/32/1127186_2.png) [@brain2412](https://forum.arduino.cc/u/brain2412)\
**Post date:** [April 19, 2025, 7:20am UTC](https://forum.arduino.cc/t/arduino-und-ws2812-nach-durchgang-alles-leds-aus-schalten/1369353/15 "2025-04-19T07:20:15Z")

</div>

Hallo  
Ich konnte das Programm noch nicht probieren da ich noch nicht zu Hause bin  
meine frage ist was bedeutet die 22 und die 23

`#define PIN_A 22// 6`

#define PIN\_B 23// 7  
Danke viele grüße

---

<div class="post-metadata">

**Author:** ![agmue](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/agmue/32/750067_2.png) [@agmue](https://forum.arduino.cc/u/agmue)\
**Post date:** [April 19, 2025, 8:16am UTC](https://forum.arduino.cc/t/arduino-und-ws2812-nach-durchgang-alles-leds-aus-schalten/1369353/16 "2025-04-19T08:16:08Z")

</div>

Das sind die Pinnummern meines ESP32, mit dem ich getestet habe, die da versehendlich stehengeblieben sind. Das gilt auch für die Pins der IR-Sensoren. Sorry!

Bitte ändere auf die ursprünglichen Pins, die Du verwenden möchtest.

---

<div class="post-metadata">

**Author:** ![brain2412](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/brain2412/32/1127186_2.png) [@brain2412](https://forum.arduino.cc/u/brain2412)\
**Post date:** [April 20, 2025, 10:13am UTC](https://forum.arduino.cc/t/arduino-und-ws2812-nach-durchgang-alles-leds-aus-schalten/1369353/17 "2025-04-20T10:13:55Z")

</div>

Hallo  
Ne ne Alles gut  
..nix sorry  
freu mich schon das zu probieren  
grüße

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [October 17, 2025, 10:14am UTC](https://forum.arduino.cc/t/arduino-und-ws2812-nach-durchgang-alles-leds-aus-schalten/1369353/18 "2025-10-17T10:14:37Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
