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);
}
}
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.
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.
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.
Thanks for the try
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!