Fehler beim Erstellen eines Lauflichtes mit 10 LED in der Schleife

Hallo, ich versuche ein Lauflicht mit 10 LED über eine Schleife (LOOP) zu erstellen, aber hier ist einiges fehlerhaft, was ist da fehlerhaft?

LEDPin=(0,1,2,3,4,5,6,7,8,9,10);
void setup() {
for (int i=0: i<=10; i++) {
// put your setup code here, to run once:
pinmode(LEDPins [i], output);
}}

// put your main code here, to run repeatedly:
void loop()
for (int i=0; i<=10; i++) {
digitalWrite (LEDPins[i]HIGH);
delay(250);
digitalwrite(LEDPins[i]LOW);
(delay0);
}
for (int i=0; i<=10; 1--) {
digitalwrite(LEDPins[1]HIGH);
delay(250);
digitalwrite (LEDPins[1]Low);
delay(0);
}}
for (int i=0; i<=10; i++) {
^

C:\Users\HP\Documents\Arduino\sketch_feb19a_copy_20260219150310_copy_2026_copy_20260228080530\sketch_feb19a_copy_20260219150310_copy_2026_copy_20260228080530.ino:16:2: error: expected unqualified-id before 'for'
  for (int i=0; i<=10; 1--)  {
  ^~~
C:\Users\HP\Documents\Arduino\sketch_feb19a_copy_20260219150310_copy_2026_copy_20260228080530\sketch_feb19a_copy_20260219150310_copy_2026_copy_20260228080530.ino:16:16: error: 'i' does not name a type
  for (int i=0; i<=10; 1--)  {
                ^
C:\Users\HP\Documents\Arduino\sketch_feb19a_copy_20260219150310_copy_2026_copy_20260228080530\sketch_feb19a_copy_20260219150310_copy_2026_copy_20260228080530.ino:16:23: error: expected unqualified-id before numeric constant
  for (int i=0; i<=10; 1--)  {
                       ^
C:\Users\HP\Documents\Arduino\sketch_feb19a_copy_20260219150310_copy_2026_copy_20260228080530\sketch_feb19a_copy_20260219150310_copy_2026_copy_20260228080530.ino:21:5: error: expected declaration before '}' token
    }}
     ^
exit status 1

Compilation error: 'LEDPin' does not name a type`Verwende dieses Symbol um Code zu posten`

Bitte bearbeite deinen Post und füge Code-Tages hinzu. Und wenn du schon dabei bist reparier bitte die Einrückung.

Ist nicht das gleiche wie LEDPins.
Mehr Sorgfalt könnte dir hier helfen

Welchen Datentyp soll dieser Pin-Array haben?

constexpr uint8_t LEDPins[]  {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

Hallo, ich bin völlig neu bei Arduino, also ich muß und will das erst einaml lernen...

Hinter loop fehlt eine Klammer

Wozu ist das gut?

Hier ein kleiner Einstieg.

constexpr uint8_t LEDPins[] { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; 

uint8_t merker = LEDPins[0];

void setup()
{
  for(const uint8_t pin : LEDPins) pinMode(pin, OUTPUT);
}

void loop()
{
  for(const uint8_t pin : LEDPins)
  {
    digitalWrite(merker, LOW);
    digitalWrite (pin, HIGH);
    merker = pin;
    delay(250);
  }
}

Kommentar:
Falls Du als Hardware einen Arduino UNO R3 benutzt:
Die Pins 0 und 1 sollten, wenn möglich frei bleiben da dort beim Arduino UNO R3 die serielle Schnittstelle liegt.

Grüße Uwe

Hallo, jetzt scheint es zu funktionieren (Danke)Verwende dieses Symbol um Code zu posten:

int LEDPins[10]={1,2,3,4,5,6,7,8,9,10};
void setup() {
for (int i=0; i<10; i++) {
// put your setup code here, to run once:
pinMode(LEDPins[i],OUTPUT);
}
}
// put your main code here, to run repeatedly:
void loop() {
for (int i=0; i<10; i++) {
digitalWrite(LEDPins[i],HIGH);
delay(250);
digitalWrite(LEDPins[i],LOW);
delay(0);
}
for (int i=9; i>0; i--) {
digitalWrite(LEDPins[1],HIGH);
delay(250);
digitalWrite(LEDPins[1],LOW);
delay(0);
}
}

.
Bitte poste code in Code Tags!

Pin-Nummern brauchen keinen int, ein byte (ist dasselbe wie uint8_t) reicht und sie ändern sich nicht.
Mit Verwendung von Pin 1 hast Du Dir den seriellen Monitor kaputt gemacht.

Schau Dir nochmal den Code von @combie an, da ist fast alles schon drin - bis auf das rückwärts laufende Licht. Du willst wohl einen K.I.T.T. nachbauen :slight_smile:

und das gäbe es auch nicht blockierend/ohne delay:

1 Like