Neopixel lights, turn on progressively

Someone could help me please with the program, I want to turn on the leds progressively and that they stay on, as now I have the program, when the leds reach their maximum brightness, they turn off again and make again the order to turn on little by little, and I want them to stay on. I'm new at this, and I don't know how to write the code to make them stay on.
Thank you!

#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
#define PIN        6
#define NUMPIXELS 10
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 500 // Time (in milliseconds) to pause between pixels
void setup() {
  pixels.begin();
}
void loop() {
  for (int i = 0; i < NUMPIXELS; i++) { 
  pixels.setPixelColor(i, 0, 0, 255);
  }
  for (int j = 255; j > 0; j=j+2)  { 
  pixels.setBrightness(j);
  pixels.show();
  delay (20);
  }
}

Why not post your code in code tags?

done sry :slight_smile:

Hi,
The first problem I see in your code is this line:
for (int j = 255; j > 0; j=j+2)
you want to go from 255 to 0 and you are adding.
correct for
for (int j = 255; j > 0; j=j -2)

The second problem is that this routine can only run once to do what you want.
Or put it inside the setup() function or create a flag to know that it has already run once.

code tags. Wonderful how those things.

So you got only one LED on at a time?

Did you know that 255,0,0 is red?
What color is 40,0,0?

Red but dimmer red?

And how to create a flag??

No, 10 LEDs light up at the same time, so far so good.
The problem is that when they have reached their maximum brightness, they turn off again and go from 0 to 255 again. And what I want is that when they turn on for the first time and have reached 255 brightness, then they stop and stay on.

before void setup() write bool flag = false;

in loop() test if flag is false;
if false run your code;
inside code set flag to true;

ok thanks! now I will try it

put the code to brighten the leds in setup() that way it only runs once/

@Idahowalker please help me. :smiley: :smiley: :smiley:

Hi,
I still haven't figured out if the error is mine or the simulator.

The LEDs go out gradually, but do not light up gradually.

Please see in the simulation;

Thanks in advance.

This is how I run a for() backwards

for( i = n; i-- > 0; )
 {
  // Use i as normal here
}

Just to make a test, I have added that after making the brightness reaches 255, the led strip changes to red, but I do not know why, the program always stays in the loop of changing the brightness and does not go beyond ...

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
#define PIN        6
#define NUMPIXELS 10
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 500 // Time (in milliseconds) to pause between pixels
bool flag = false;
void setup() {
  pixels.begin();
 
}
void loop() {
 
  for (int i = 0; i < NUMPIXELS; i++) { 
  pixels.setPixelColor(i, 0, 0, 255);
  }
  for (int j = 255; j > 0; j=j+2)  { 
  pixels.setBrightness(j);
  pixels.show();
  delay (20);
}
  for (int i = 0; i < NUMPIXELS; i++) { 
  pixels.setPixelColor(i, 255, 0, 0);
  }
  
}

If you want the leds to brighten one time put the led brighten code in setup().

setup() only runs once.

loop() runs many many many many many many many many many many many many many many many many many many many many many many many many many many many times.

I have done it and it does the same thing, when it reaches maximum brightness it repeats itself.

where is the "I have done it code" that only brightens the leds in setup()?

Anyways, this is getting to be like pulling teeth and I'm not getting paid. Perhaps someone else will have the patience to help you. Good luck.

thanks!

Hi,
this code should work, but I'm having problems with it.

See the thread I created:

Thanks for the try :slight_smile:
I'm trying several options as well, but I'm not getting anything at the moment.
The code you have done does work, the only thing I would like is that the light instead of turning off, turns on, and when I make these changes, it stops working xD.
Thanks anyway!

see the other post...

1 Like