Reverse led strip neopixel

hey guys so i tried everything i know on this sample program to let the leds run from last led to first led but dont know how to change the for function...

static void chase(uint32_t c) {
  for(uint16_t i=0; i<strip.numPixels()+4; i++) {
      strip.setPixelColor(i  , c); // Draw new pixel
      strip.setPixelColor(i-4, 0); // Erase pixel a few steps back
      strip.show();
      delay(25);
  }
}

This goes from 0 to (beyond) the end of the strip

What could it be to go the other ways…?

for(uint16_t i=144; i>1()-4; i--) {

well i tried this

static void chase(uint32_t c) {
  for(int16_t i=strip.numPixels(); i>=-4; i--) {
      if(i>=0) strip.setPixelColor(i  , c); // Draw new pixel
      if(i<strip.numPixels()-4) strip.setPixelColor(i+4, 0); // Erase pixel a few steps back
      strip.show();
      delay(25);
  }
}

holy moly thanks i thaught its just a few changes this is basically new code

I hope I fixed some of the errors in the original code you posted (pointed out by @J-M-L ).

What’s that supposed to do? Why the parenthesis?

i have no idea just got the code like that from the internet

From a dumpster! :slight_smile:

]

I did not offer a correction there because the library does the check so it won’t do stupid stuff.

Ah, I had forgotten the Adafruit library does that!

But the FastLED library does not, for example.

u guys are awsome do u guys know where to lewarn these stuff best site or so?

I began writing code in about 1980 and went on to study it at university!

1 Like

so the first code i posted lets 4 leds run from left to right
the code you guys fixed lets the leds run from right to left
is there a way so that the leds runs from left and right togheter to meet at the middel and then back to the sides where they came from?

wow i didnt know it was possible to study code at that time

1 Like

Yes, it can be done.

But I already gave you a fish today. Practice your fishing skills.

thanks ok one question that would maby assist as i tip would i do it with more ifs in the same code aswell with another i but not using i maby like j or so

I wrote my first computer program in 1970, when I was studying Physics at University. And even then it wasn't new. The first high level language called Colbol was introduced in the mid 50s with the claim that now anyone could program a computer.

Before that in the 40s you had to use machine code in order to run a computer. I met one person who did that, when I was teaching at a University.

@r2w2 Sorry, I can't understand you last post.