Closed anto168 closed 1 year ago
I'm not sure what a "potentio function" is. Can you elaborate?
potentio to adjust the speed of the animation.
Oh, you're talking about a potentiometer. What kind of microprocessor are you using?
micro, arduino nano
It's been a long time since I played LED, the sketch that I made is lost because the computer is broken, can you help me to make a basic ws2812fx.
I want to make a decoration at home, with 1 led strip with 3 segments of fade animation, segment 1 lights up fades then moves to the next segment without turning off the previous segment.
i am trying to use arduino nano.
basic 3 segments
Controlling the brightness of each segment independently isn't so easy with ws2812fx. You can use the setBrightness() function to control the global strip brightness, but there's no corresponding function for controlling an individual segment's brightness.
But I took it as a challenge and came up with this example sketch, which includes fading in each segment, one after the other, and some code to control the animation speed with a potentiometer:
#include <WS2812FX.h>
#define ANALOG_PIN A0 // analog pin connected to the potentiometer
#define LED_PIN 3 // digital pin used to drive the LED strip
#define LED_COUNT 24 // number of LEDs on the strip
WS2812FX ws2812fx = WS2812FX(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
unsigned long timer = 0;
unsigned long debugTimer = 0;
const uint32_t segColors[3] = {RED, GREEN, BLUE}; // initial color values of each of the three segments
int segBrights[3] = {0, 0, 0}; // initial brightness values for each of the three segments
int potValue = 0;
uint16_t speedValue = 0;
void setup() {
Serial.begin(115200);
ws2812fx.init();
ws2812fx.setBrightness(255);
// parameters: index, start, stop, mode, color, speed, reverse
ws2812fx.setSegment(0, 0, 7, FX_MODE_THEATER_CHASE, RED, 1000); // segment 0
ws2812fx.setSegment(1, 8, 15, FX_MODE_SCAN, GREEN, 1000); // segment 1
ws2812fx.setSegment(2, 16, 23, FX_MODE_COMET, BLUE, 1000); // segment 2
ws2812fx.start();
}
void loop() {
ws2812fx.service();
// update speed and brightness every 20ms
if(millis() > timer + 20) {
potValue = analogRead(ANALOG_PIN); // get the potentiometer value (0 - 1023)
speedValue = map(potValue, 0, 1023, 40, 2000); // scale the pot value to a speed value
if(segBrights[0] < 255) { // increase each segment's brightness one after another
segBrights[0]++;
} else if(segBrights[1] < 255) {
segBrights[1]++;
} else if(segBrights[2] < 255) {
segBrights[2]++;
} else {
segBrights[0] = 0; // when all segments reach full brightness, reset brightnesses
segBrights[1] = 0;
segBrights[2] = 0;
ws2812fx.clear();
}
// update each segment
for(int i=0; i<3; i++) {
uint32_t newColor = ws2812fx.color_blend(BLACK, segColors[i], segBrights[i]); // calc blended color (initial color modified by current brightness)
ws2812fx.setColor(i, newColor); // assign modified color to each segment
ws2812fx.setSpeed(i, speedValue); // assign speed to each segment
}
timer = millis();
}
if(millis() > debugTimer + 1000) { // debug message every 1 second
Serial.print("brightnesses:"); Serial.print(segBrights[0]); Serial.print(", "); Serial.print(segBrights[1]); Serial.print(", "); Serial.println(segBrights[2]);
Serial.print("potValue:"); Serial.println(potValue);
Serial.print("speedValue:"); Serial.println(speedValue);
debugTimer = millis();
}
}
The sketch fades in each segment by using a segBrights[] array to keep track of each segment's brightness, and uses that to blend the segment's initial color with BLACK to yield a new color with the correct brightness. It doesn't work with all effects (notably the rainbow effects don't use a segment's assigned color, so they would be unaffected by the fade-in code), but it might be good enough for what you want to accomplish.
The potentiometer is connected as shown in this tutorial: https://docs.arduino.cc/built-in-examples/basics/AnalogReadSerial
thank you for helping me, I have made and modified your code from you.
may I ask something else, about fastled, I tried to make a code like this, how do I adjust the brightness on case 4 so that it lights up from dim to bright.
CRGB leds[NUM_LEDS]; int frameIndex = 0;
int nextFrameIndex() { if (frameIndex < MAX_FRAMES - 1) { return frameIndex + 1; } else { return 0; } }
void setup() { FastLED.addLeds<WS2811, DATA_PIN, GRB>(leds, NUM_LEDS); FastLED.setBrightness(200); // Frame 1 leds[0].setRGB(255, 255, 255); leds[1].setRGB(0, 0, 0); leds[2].setRGB(0, 0, 0); leds[3].setRGB(0, 0, 0); leds[4].setRGB(0, 0, 0); leds[5].setRGB(0, 0, 0); leds[6].setRGB(0, 0, 0); leds[7].setRGB(0, 0, 0); leds[8].setRGB(0, 0, 0); leds[9].setRGB(0, 0, 0);
}
void loop() { EVERY_N_MILLISECONDS(500) { frameIndex = nextFrameIndex(); setColors(); } FastLED.show(); }
void setColors() { switch (frameIndex) { case 0: leds[0].setRGB(255, 255, 255); leds[1].setRGB(0, 0, 0); leds[2].setRGB(0, 0, 0); leds[3].setRGB(0, 0, 0); leds[4].setRGB(0, 0, 0); leds[5].setRGB(0, 0, 0); leds[6].setRGB(0, 0, 0); leds[7].setRGB(0, 0, 0); leds[8].setRGB(0, 0, 0); leds[9].setRGB(0, 0, 0); break; case 1: leds[1].setRGB(255, 255, 255); break; case 2: leds[2].setRGB(255, 255, 255); leds[3].setRGB(255, 255, 255); break; case 3: leds[4].setRGB(255, 255, 255); break; case 4: leds[5].setRGB(255, 255, 255); leds[6].setRGB(255, 255, 255); leds[7].setRGB(255, 255, 255); leds[8].setRGB(255, 255, 255); leds[9].setRGB(255, 255, 255); break; case 5: leds[0].setRGB(0, 0, 0); leds[1].setRGB(0, 0, 0); leds[2].setRGB(0, 0, 0); leds[3].setRGB(0, 0, 0); leds[4].setRGB(0, 0, 0); leds[5].setRGB(0, 0, 0); leds[6].setRGB(0, 0, 0); leds[7].setRGB(0, 0, 0); leds[8].setRGB(0, 0, 0); leds[9].setRGB(0, 0, 0); break; case 6: leds[0].setRGB(255, 255, 255); leds[1].setRGB(255, 255, 255); leds[2].setRGB(255, 255, 255); leds[3].setRGB(255, 255, 255); leds[4].setRGB(255, 255, 255); leds[5].setRGB(255, 255, 255); leds[6].setRGB(255, 255, 255); leds[7].setRGB(255, 255, 255); leds[8].setRGB(255, 255, 255); leds[9].setRGB(255, 255, 255); break; case 7: leds[0].setRGB(0, 0, 0); leds[1].setRGB(0, 0, 0); leds[2].setRGB(0, 0, 0); leds[3].setRGB(0, 0, 0); leds[4].setRGB(0, 0, 0); leds[5].setRGB(0, 0, 0); leds[6].setRGB(0, 0, 0); leds[7].setRGB(0, 0, 0); leds[8].setRGB(0, 0, 0); leds[9].setRGB(0, 0, 0); break;
}
}
I'm not sure exactly what you're after. Do you just want to fade-in the 5 LEDs in case 4?
You can use the nscale8() function to adjust each individual LED's brightness. I came up with this:
#include <FastLED.h>
#define NUM_LEDS 10
#define DATA_PIN 2
#define MAX_FRAMES 8
#define FRAME_DELAY 500 // ms per frame
#define FADE_DELAY (FRAME_DELAY / 256) // ms per fade step
CRGB leds[NUM_LEDS];
int frameIndex = 0;
int nextFrameIndex() {
if (frameIndex < MAX_FRAMES - 1) {
return frameIndex + 1;
} else {
return 0;
}
}
int fadeAmount = 0;
void setup() {
FastLED.addLeds<WS2811, DATA_PIN, GRB>(leds, NUM_LEDS);
FastLED.setBrightness(200);
// Frame 1
leds[0].setRGB(255, 255, 255);
leds[1].setRGB(0, 0, 0);
leds[2].setRGB(0, 0, 0);
leds[3].setRGB(0, 0, 0);
leds[4].setRGB(0, 0, 0);
leds[5].setRGB(0, 0, 0);
leds[6].setRGB(0, 0, 0);
leds[7].setRGB(0, 0, 0);
leds[8].setRGB(0, 0, 0);
leds[9].setRGB(0, 0, 0);
}
void loop() {
EVERY_N_MILLISECONDS( FRAME_DELAY ) { // this loop controls the frame rate
frameIndex = nextFrameIndex();
fadeAmount = 0; // reset the fadeAmount at the beginning of each frame
}
EVERY_N_MILLISECONDS( FADE_DELAY ) { // this loop controls the fade rate
if(fadeAmount < 255) fadeAmount++; // increment the fadeAmount for each call to show()
setColors();
FastLED.show();
}
}
void setColors() {
switch (frameIndex) {
case 0:
leds[0].setRGB(255, 255, 255);
leds[1].setRGB(0, 0, 0);
leds[2].setRGB(0, 0, 0);
leds[3].setRGB(0, 0, 0);
leds[4].setRGB(0, 0, 0);
leds[5].setRGB(0, 0, 0);
leds[6].setRGB(0, 0, 0);
leds[7].setRGB(0, 0, 0);
leds[8].setRGB(0, 0, 0);
leds[9].setRGB(0, 0, 0);
break;
case 1:
leds[1].setRGB(255, 255, 255);
break;
case 2:
leds[2].setRGB(255, 255, 255);
leds[3].setRGB(255, 255, 255);
break;
case 3:
leds[4].setRGB(255, 255, 255);
break;
case 4:
leds[5].setRGB(255, 255, 255); leds[5].nscale8(fadeAmount);
leds[6].setRGB(255, 255, 255); leds[6].nscale8(fadeAmount);
leds[7].setRGB(255, 255, 255); leds[7].nscale8(fadeAmount);
leds[8].setRGB(255, 255, 255); leds[8].nscale8(fadeAmount);
leds[9].setRGB(255, 255, 255); leds[9].nscale8(fadeAmount);
break;
case 5:
leds[0].setRGB(0, 0, 0);
leds[1].setRGB(0, 0, 0);
leds[2].setRGB(0, 0, 0);
leds[3].setRGB(0, 0, 0);
leds[4].setRGB(0, 0, 0);
leds[5].setRGB(0, 0, 0);
leds[6].setRGB(0, 0, 0);
leds[7].setRGB(0, 0, 0);
leds[8].setRGB(0, 0, 0);
leds[9].setRGB(0, 0, 0);
break;
case 6:
leds[0].setRGB(255, 255, 255);
leds[1].setRGB(255, 255, 255);
leds[2].setRGB(255, 255, 255);
leds[3].setRGB(255, 255, 255);
leds[4].setRGB(255, 255, 255);
leds[5].setRGB(255, 255, 255);
leds[6].setRGB(255, 255, 255);
leds[7].setRGB(255, 255, 255);
leds[8].setRGB(255, 255, 255);
leds[9].setRGB(255, 255, 255);
break;
case 7:
leds[0].setRGB(0, 0, 0);
leds[1].setRGB(0, 0, 0);
leds[2].setRGB(0, 0, 0);
leds[3].setRGB(0, 0, 0);
leds[4].setRGB(0, 0, 0);
leds[5].setRGB(0, 0, 0);
leds[6].setRGB(0, 0, 0);
leds[7].setRGB(0, 0, 0);
leds[8].setRGB(0, 0, 0);
leds[9].setRGB(0, 0, 0);
break;
}
}
I'm not a FastLED expert, so there may be a better way to do this, but maybe this'll get you started.
so when you enter case 4, on case 4 it doesn't light up immediately, but from dim to bright then moves to case 5.
like fade in, from dim to bright.
Can this value setting be changed, using a potentiometer?
Sure. See my earlier sketch. Make FRAME_DELAY and FADE_DELAY variables. Then read the pot value and scale the pot value to a suitable range.
int potValue = analogRead(ANALOG_PIN); // get the potentiometer value (0 - 1023)
int frameDelay = map(potValue, 0, 1023, 500, 5000); // scale the pot value to a suitable frameDelay
int fadeDelay = frameDelay / 256;
CRGB leds[NUM_LEDS]; int frameIndex = 0;
int potValue = analogRead(A0);
int frameDelay = map(potValue, 0, 1023, 500, 5000);
int fadeDelay = frameDelay / 256;
int nextFrameIndex() { if (frameIndex < MAX_FRAMES - 1) { return frameIndex + 1; } else { return 0; } }
int fadeAmount = 0;
void setup() { FastLED.addLeds<WS2811, DATA_PIN, GRB>(leds, NUM_LEDS); FastLED.setBrightness(200); // Frame 1 leds[0].setRGB(255, 255, 255); leds[1].setRGB(0, 0, 0); leds[2].setRGB(0, 0, 0); leds[3].setRGB(0, 0, 0); leds[4].setRGB(0, 0, 0); leds[5].setRGB(0, 0, 0); leds[6].setRGB(0, 0, 0); leds[7].setRGB(0, 0, 0); leds[8].setRGB(0, 0, 0); leds[9].setRGB(0, 0, 0); }
void loop() { EVERY_N_MILLISECONDS( FRAME_DELAY ) { // this loop controls the frame rate frameIndex = nextFrameIndex(); fadeAmount = 0; // reset the fadeAmount at the beginning of each frame }
EVERY_N_MILLISECONDS( FADE_DELAY ) { // this loop controls the fade rate if(fadeAmount < 255) fadeAmount++; // increment the fadeAmount for each call to show() setColors(); FastLED.show(); } }
void setColors() { switch (frameIndex) { case 0: leds[0].setRGB(255, 255, 255); leds[1].setRGB(0, 0, 0); leds[2].setRGB(0, 0, 0); leds[3].setRGB(0, 0, 0); leds[4].setRGB(0, 0, 0); leds[5].setRGB(0, 0, 0); leds[6].setRGB(0, 0, 0); leds[7].setRGB(0, 0, 0); leds[8].setRGB(0, 0, 0); leds[9].setRGB(0, 0, 0); break; case 1: leds[1].setRGB(255, 255, 255); break; case 2: leds[2].setRGB(255, 255, 255); leds[3].setRGB(255, 255, 255); break; case 3: leds[4].setRGB(255, 255, 255); break; case 4: leds[5].setRGB(255, 255, 255); leds[5].nscale8(fadeAmount); leds[6].setRGB(255, 255, 255); leds[6].nscale8(fadeAmount); leds[7].setRGB(255, 255, 255); leds[7].nscale8(fadeAmount); leds[8].setRGB(255, 255, 255); leds[8].nscale8(fadeAmount); leds[9].setRGB(255, 255, 255); leds[9].nscale8(fadeAmount); break; case 5: leds[0].setRGB(0, 0, 0); leds[1].setRGB(0, 0, 0); leds[2].setRGB(0, 0, 0); leds[3].setRGB(0, 0, 0); leds[4].setRGB(0, 0, 0); leds[5].setRGB(0, 0, 0); leds[6].setRGB(0, 0, 0); leds[7].setRGB(0, 0, 0); leds[8].setRGB(0, 0, 0); leds[9].setRGB(0, 0, 0); break; case 6: leds[0].setRGB(255, 255, 255); leds[1].setRGB(255, 255, 255); leds[2].setRGB(255, 255, 255); leds[3].setRGB(255, 255, 255); leds[4].setRGB(255, 255, 255); leds[5].setRGB(255, 255, 255); leds[6].setRGB(255, 255, 255); leds[7].setRGB(255, 255, 255); leds[8].setRGB(255, 255, 255); leds[9].setRGB(255, 255, 255); break; case 7: leds[0].setRGB(0, 0, 0); leds[1].setRGB(0, 0, 0); leds[2].setRGB(0, 0, 0); leds[3].setRGB(0, 0, 0); leds[4].setRGB(0, 0, 0); leds[5].setRGB(0, 0, 0); leds[6].setRGB(0, 0, 0); leds[7].setRGB(0, 0, 0); leds[8].setRGB(0, 0, 0); leds[9].setRGB(0, 0, 0); break; } }
sorry is it like this, . I tried it doesn't work.
Hmmm...you seem to be pretty new at this. You should probably review Adafruit's Neopixel Uberguide to get familiar with programming wS2812 LEDs. The Adafruit Neopixel library's example sketches can be a good learning tool too.
To fix your sketch, move the new potentiometer code to the beginning of the loop() function, and change FRAME_DELAY and FADE_DELAY to frameDelay and fadeDelay, respectively.
CRGB leds[NUM_LEDS]; int frameIndex = 0;
int potValue = analogRead(A0); int frameDelay = map(potValue, 0, 1023, 500,5000); int fadeDelay = frameDelay / 256; int speedValue = 0
int nextFrameIndex() { if (frameIndex < MAX_FRAMES - 1) { return frameIndex + 1; } else { return 0; } }
int fadeAmount = 0;
void setup() { FastLED.addLeds<WS2811, DATA_PIN, GRB>(leds, NUM_LEDS); FastLED.setBrightness(200); // Frame 1 leds[0].setRGB(255, 255, 255); leds[1].setRGB(0, 0, 0); leds[2].setRGB(0, 0, 0); leds[3].setRGB(0, 0, 0); leds[4].setRGB(0, 0, 0); leds[5].setRGB(0, 0, 0); leds[6].setRGB(0, 0, 0); leds[7].setRGB(0, 0, 0); leds[8].setRGB(0, 0, 0); leds[9].setRGB(0, 0, 0); }
void loop() { EVERY_N_MILLISECONDS( frameDelay) { // this loop controls the frame rate frameIndex = nextFrameIndex(); potValue = analogRead(ANALOG_PIN); speedValue = map(potValue, 0, 1023, 500, 5000);
fadeAmount = 0; // reset the fadeAmount at the beginning of each frame }
EVERY_N_MILLISECONDS( fadeDelay ) { // this loop controls the fade rate if(fadeAmount < 255) fadeAmount++; // increment the fadeAmount for each call to show() setColors(); FastLED.show(); } }
void setColors() { switch (frameIndex) { case 0: leds[0].setRGB(255, 255, 255); leds[1].setRGB(0, 0, 0); leds[2].setRGB(0, 0, 0); leds[3].setRGB(0, 0, 0); leds[4].setRGB(0, 0, 0); leds[5].setRGB(0, 0, 0); leds[6].setRGB(0, 0, 0); leds[7].setRGB(0, 0, 0); leds[8].setRGB(0, 0, 0); leds[9].setRGB(0, 0, 0); break; case 1: leds[1].setRGB(255, 255, 255); break; case 2: leds[2].setRGB(255, 255, 255); leds[3].setRGB(255, 255, 255); break; case 3: leds[4].setRGB(255, 255, 255); break; case 4: leds[5].setRGB(255, 255, 255); leds[5].nscale8(fadeAmount); leds[6].setRGB(255, 255, 255); leds[6].nscale8(fadeAmount); leds[7].setRGB(255, 255, 255); leds[7].nscale8(fadeAmount); leds[8].setRGB(255, 255, 255); leds[8].nscale8(fadeAmount); leds[9].setRGB(255, 255, 255); leds[9].nscale8(fadeAmount); break; case 5: leds[0].setRGB(0, 0, 0); leds[1].setRGB(0, 0, 0); leds[2].setRGB(0, 0, 0); leds[3].setRGB(0, 0, 0); leds[4].setRGB(0, 0, 0); leds[5].setRGB(0, 0, 0); leds[6].setRGB(0, 0, 0); leds[7].setRGB(0, 0, 0); leds[8].setRGB(0, 0, 0); leds[9].setRGB(0, 0, 0); break; case 6: leds[0].setRGB(255, 255, 255); leds[1].setRGB(255, 255, 255); leds[2].setRGB(255, 255, 255); leds[3].setRGB(255, 255, 255); leds[4].setRGB(255, 255, 255); leds[5].setRGB(255, 255, 255); leds[6].setRGB(255, 255, 255); leds[7].setRGB(255, 255, 255); leds[8].setRGB(255, 255, 255); leds[9].setRGB(255, 255, 255); break; case 7: leds[0].setRGB(0, 0, 0); leds[1].setRGB(0, 0, 0); leds[2].setRGB(0, 0, 0); leds[3].setRGB(0, 0, 0); leds[4].setRGB(0, 0, 0); leds[5].setRGB(0, 0, 0); leds[6].setRGB(0, 0, 0); leds[7].setRGB(0, 0, 0); leds[8].setRGB(0, 0, 0); leds[9].setRGB(0, 0, 0); break; } }
sorry, is this what you mean?
No, I was thinking of this:
void loop() {
int potValue = analogRead(A0); // get the potentiometer value (0 - 1023)
int frameDelay = map(potValue, 0, 1023, 500, 5000); // scale the pot value to a suitable frameDelay
int fadeDelay = frameDelay / 256;
EVERY_N_MILLISECONDS( frameDelay ) { // this loop controls the frame rate
frameIndex = nextFrameIndex();
fadeAmount = 0; // reset the fadeAmount at the beginning of each frame
}
EVERY_N_MILLISECONDS( fadeDelay ) { // this loop controls the fade rate
if(fadeAmount < 255) fadeAmount++; // increment the fadeAmount for each call to show()
setColors();
FastLED.show();
}
}
I haven't used EVERY_N_MILLISECONDS in this way before, so I'm not sure this will work. I'll try to test it tomorrow.
I have tried to enter this program but can not,
You're right, EVERY_N_MILLISECONDS doesn't work with a variable delay. But FastLED provides the EVERY_N_MILLISECONDS_I macro (note the "_I" at the end) that does work. Here's my test sketch:
#include <FastLED.h>
#define NUM_LEDS 10
#define DATA_PIN 2
#define MAX_FRAMES 8
//#define FRAME_DELAY 500 // ms per frame
//#define FADE_DELAY (FRAME_DELAY / 256) // ms per fade step
CRGB leds[NUM_LEDS];
int frameIndex = 0;
int nextFrameIndex() {
if (frameIndex < MAX_FRAMES - 1) {
return frameIndex + 1;
} else {
return 0;
}
}
int fadeAmount = 0;
void setup() {
FastLED.addLeds<WS2811, DATA_PIN, GRB>(leds, NUM_LEDS);
FastLED.setBrightness(200);
// Frame 1
leds[0].setRGB(255, 255, 255);
leds[1].setRGB(0, 0, 0);
leds[2].setRGB(0, 0, 0);
leds[3].setRGB(0, 0, 0);
leds[4].setRGB(0, 0, 0);
leds[5].setRGB(0, 0, 0);
leds[6].setRGB(0, 0, 0);
leds[7].setRGB(0, 0, 0);
leds[8].setRGB(0, 0, 0);
leds[9].setRGB(0, 0, 0);
}
void loop() {
int potValue = analogRead(A0); // get the potentiometer value (0 - 1023)
int frameDelay = map(potValue, 0, 1023, 256, 2048); // scale the pot value to a suitable frameDelay
EVERY_N_MILLISECONDS_I( frameTimer, 512) { // this loop controls the frame rate
frameTimer.setPeriod( frameDelay ); // update the frame rate based on potentiometer setting
frameIndex = nextFrameIndex();
fadeAmount = 0; // reset the fadeAmount at the beginning of each frame
}
EVERY_N_MILLISECONDS_I( fadeTimer, 2) { // this loop controls the fade rate
fadeTimer.setPeriod( frameDelay / 256 ); // update the fade rate based on potentiometer setting
if(fadeAmount < 255) fadeAmount++; // increment the fadeAmount for each call to show()
setColors();
FastLED.show();
}
}
void setColors() {
switch (frameIndex) {
case 0:
leds[0].setRGB(255, 255, 255);
leds[1].setRGB(0, 0, 0);
leds[2].setRGB(0, 0, 0);
leds[3].setRGB(0, 0, 0);
leds[4].setRGB(0, 0, 0);
leds[5].setRGB(0, 0, 0);
leds[6].setRGB(0, 0, 0);
leds[7].setRGB(0, 0, 0);
leds[8].setRGB(0, 0, 0);
leds[9].setRGB(0, 0, 0);
break;
case 1:
leds[1].setRGB(255, 255, 255);
break;
case 2:
leds[2].setRGB(255, 255, 255);
leds[3].setRGB(255, 255, 255);
break;
case 3:
leds[4].setRGB(255, 255, 255);
break;
case 4:
leds[5].setRGB(255, 255, 255); leds[5].nscale8(fadeAmount);
leds[6].setRGB(255, 255, 255); leds[6].nscale8(fadeAmount);
leds[7].setRGB(255, 255, 255); leds[7].nscale8(fadeAmount);
leds[8].setRGB(255, 255, 255); leds[8].nscale8(fadeAmount);
leds[9].setRGB(255, 255, 255); leds[9].nscale8(fadeAmount);
break;
case 5:
fill_solid(leds, NUM_LEDS, CRGB::Black);
// leds[0].setRGB(0, 0, 0);
// leds[1].setRGB(0, 0, 0);
// leds[2].setRGB(0, 0, 0);
// leds[3].setRGB(0, 0, 0);
// leds[4].setRGB(0, 0, 0);
// leds[5].setRGB(0, 0, 0);
// leds[6].setRGB(0, 0, 0);
// leds[7].setRGB(0, 0, 0);
// leds[8].setRGB(0, 0, 0);
// leds[9].setRGB(0, 0, 0);
break;
case 6:
fill_solid(leds, NUM_LEDS, CRGB::White);
// leds[0].setRGB(255, 255, 255);
// leds[1].setRGB(255, 255, 255);
// leds[2].setRGB(255, 255, 255);
// leds[3].setRGB(255, 255, 255);
// leds[4].setRGB(255, 255, 255);
// leds[5].setRGB(255, 255, 255);
// leds[6].setRGB(255, 255, 255);
// leds[7].setRGB(255, 255, 255);
// leds[8].setRGB(255, 255, 255);
// leds[9].setRGB(255, 255, 255);
break;
case 7:
fill_solid(leds, NUM_LEDS, CRGB::Black);
// leds[0].setRGB(0, 0, 0);
// leds[1].setRGB(0, 0, 0);
// leds[2].setRGB(0, 0, 0);
// leds[3].setRGB(0, 0, 0);
// leds[4].setRGB(0, 0, 0);
// leds[5].setRGB(0, 0, 0);
// leds[6].setRGB(0, 0, 0);
// leds[7].setRGB(0, 0, 0);
// leds[8].setRGB(0, 0, 0);
// leds[9].setRGB(0, 0, 0);
break;
}
}
sketch can run well, thanks a lot for helping and teaching me, I got new experiences about sketch...
hello, I want to ask again, on the fade delay, when I use more LEDs, why does the fadeAmount have a different contrast, the results are dimmer.
Hmmmm, I'm not sure. Adding for LEDs would cause the loop() to run slower, but I think you'd have to be driving hundreds of LEDs for that to cause enough delay to be a problem. How many LEDs are you trying to use?
i tried to use 100 pixels, the led which is in the fade position, it becomes dimmer not bright like the others, but if i use 30 pixels, the contrast of all the leds is the same.
I tried 100 LEDs and I don't see the problem you're describing. The LEDs fade-in to full brightness for me. Maybe you could show me your sketch.
I use your sketch, I only add it to 100 pixels. for fade the contrast is not full, but the others are normal full contrast.
sketch
CRGB leds[NUM_LEDS]; int frameIndex = 0; int nextFrameIndex() { if (frameIndex < MAX_FRAMES - 1) { return frameIndex + 1; } else { return 0; } } int fadeAmount = 0; void setup() { FastLED.addLeds<WS2811, DATA_PIN, GRB>(leds, NUM_LEDS); FastLED.setBrightness(255); // Frame 1 leds[0].setRGB(0, 0, 0); leds[1].setRGB(0, 0, 0); leds[2].setRGB(0, 0, 0); leds[3].setRGB(0, 0, 0); leds[4].setRGB(0, 0, 0); leds[5].setRGB(0, 0, 0); leds[6].setRGB(0, 0, 0); leds[7].setRGB(0, 0, 0); leds[8].setRGB(0, 0, 0); leds[9].setRGB(0, 0, 0); leds[10].setRGB(0, 0, 0); leds[11].setRGB(0, 0, 0); leds[12].setRGB(0, 0, 0); leds[13].setRGB(0, 0, 0); leds[14].setRGB(0, 0, 0); leds[15].setRGB(0, 0, 0); leds[16].setRGB(0, 0, 0); leds[17].setRGB(0, 0, 0); leds[18].setRGB(0, 0, 0); leds[19].setRGB(0, 0, 0); leds[20].setRGB(0, 0, 0); leds[21].setRGB(0, 0, 0); leds[22].setRGB(0, 0, 0); leds[23].setRGB(0, 0, 0); leds[24].setRGB(0, 0, 0); leds[25].setRGB(0, 0, 0); leds[26].setRGB(0, 0, 0); leds[27].setRGB(0, 0, 0); leds[28].setRGB(0, 0, 0); leds[29].setRGB(0, 0, 0); leds[30].setRGB(0, 0, 0);
leds[31].setRGB(0, 0, 0); leds[32].setRGB(0, 0, 0); leds[33].setRGB(0, 0, 0); leds[34].setRGB(0, 0, 0); leds[35].setRGB(0, 0, 0); leds[36].setRGB(0, 0, 0); leds[37].setRGB(0, 0, 0); leds[38].setRGB(0, 0, 0); leds[39].setRGB(0, 0, 0); leds[40].setRGB(0, 0, 0); leds[41].setRGB(0, 0, 0); leds[42].setRGB(0, 0, 0); leds[43].setRGB(0, 0, 0); leds[44].setRGB(0, 0, 0); leds[45].setRGB(0, 0, 0); leds[46].setRGB(0, 0, 0); leds[47].setRGB(0, 0, 0); leds[48].setRGB(0, 0, 0); leds[49].setRGB(0, 0, 0); leds[50].setRGB(0, 0, 0); leds[51].setRGB(0, 0, 0); leds[52].setRGB(0, 0, 0); leds[53].setRGB(0, 0, 0); leds[54].setRGB(0, 0, 0); leds[55].setRGB(0, 0, 0); leds[56].setRGB(0, 0, 0); leds[57].setRGB(0, 0, 0); leds[58].setRGB(0, 0, 0); leds[59].setRGB(0, 0, 0); leds[60].setRGB(0, 0, 0);
leds[61].setRGB(0, 0, 0); leds[62].setRGB(0, 0, 0); leds[63].setRGB(0, 0, 0); leds[64].setRGB(0, 0, 0); leds[65].setRGB(0, 0, 0); leds[66].setRGB(0, 0, 0); leds[67].setRGB(0, 0, 0); leds[68].setRGB(0, 0, 0); leds[69].setRGB(0, 0, 0); leds[70].setRGB(0, 0, 0); leds[71].setRGB(0, 0, 0); leds[72].setRGB(0, 0, 0); leds[73].setRGB(0, 0, 0); leds[74].setRGB(0, 0, 0); leds[75].setRGB(0, 0, 0); leds[76].setRGB(0, 0, 0); leds[77].setRGB(0, 0, 0); leds[78].setRGB(0, 0, 0); leds[79].setRGB(0, 0, 0); leds[80].setRGB(0, 0, 0); leds[81].setRGB(0, 0, 0); leds[82].setRGB(0, 0, 0); leds[83].setRGB(0, 0, 0); leds[84].setRGB(0, 0, 0); leds[85].setRGB(0, 0, 0); leds[86].setRGB(0, 0, 0); leds[87].setRGB(0, 0, 0); leds[88].setRGB(0, 0, 0); leds[89].setRGB(0, 0, 0); leds[90].setRGB(0, 0, 0);
leds[91].setRGB(0, 0, 0); leds[92].setRGB(0, 0, 0); leds[93].setRGB(0, 0, 0); leds[94].setRGB(0, 0, 0); leds[95].setRGB(0, 0, 0); leds[96].setRGB(0, 0, 0); leds[97].setRGB(0, 0, 0); leds[98].setRGB(0, 0, 0); leds[99].setRGB(0, 0, 0); leds[100].setRGB(0, 0, 0); leds[101].setRGB(0, 0, 0); leds[102].setRGB(0, 0, 0); leds[103].setRGB(0, 0, 0); leds[104].setRGB(0, 0, 0); leds[105].setRGB(0, 0, 0); leds[106].setRGB(0, 0, 0); leds[107].setRGB(0, 0, 0); leds[108].setRGB(0, 0, 0); leds[109].setRGB(0, 0, 0); leds[110].setRGB(0, 0, 0); leds[111].setRGB(0, 0, 0); leds[112].setRGB(0, 0, 0); leds[113].setRGB(0, 0, 0); leds[114].setRGB(0, 0, 0); leds[115].setRGB(0, 0, 0); leds[116].setRGB(0, 0, 0); leds[117].setRGB(0, 0, 0); leds[118].setRGB(0, 0, 0); leds[119].setRGB(0, 0, 0); leds[120].setRGB(0, 0, 0);
leds[121].setRGB(0, 0, 0); leds[122].setRGB(0, 0, 0); leds[123].setRGB(0, 0, 0); leds[124].setRGB(0, 0, 0); leds[125].setRGB(0, 0, 0); leds[126].setRGB(0, 0, 0); leds[127].setRGB(0, 0, 0); leds[128].setRGB(0, 0, 0); leds[129].setRGB(0, 0, 0); leds[130].setRGB(0, 0, 0); leds[131].setRGB(0, 0, 0); leds[132].setRGB(0, 0, 0); leds[133].setRGB(0, 0, 0); leds[134].setRGB(0, 0, 0); leds[135].setRGB(0, 0, 0); leds[136].setRGB(0, 0, 0); leds[137].setRGB(0, 0, 0); leds[138].setRGB(0, 0, 0); leds[139].setRGB(0, 0, 0); leds[140].setRGB(0, 0, 0); leds[141].setRGB(0, 0, 0); leds[142].setRGB(0, 0, 0); leds[143].setRGB(0, 0, 0); leds[144].setRGB(0, 0, 0); leds[145].setRGB(0, 0, 0); leds[146].setRGB(0, 0, 0); leds[147].setRGB(0, 0, 0); leds[148].setRGB(0, 0, 0); leds[149].setRGB(0, 0, 0); leds[150].setRGB(0, 0, 0);
leds[151].setRGB(0, 0, 0); leds[152].setRGB(0, 0, 0); leds[153].setRGB(0, 0, 0); leds[154].setRGB(0, 0, 0); leds[155].setRGB(0, 0, 0); leds[156].setRGB(0, 0, 0); leds[157].setRGB(0, 0, 0); leds[158].setRGB(0, 0, 0); leds[159].setRGB(0, 0, 0); leds[160].setRGB(0, 0, 0); leds[161].setRGB(0, 0, 0); leds[162].setRGB(0, 0, 0); leds[163].setRGB(0, 0, 0); leds[164].setRGB(0, 0, 0); leds[165].setRGB(0, 0, 0); leds[166].setRGB(0, 0, 0); leds[167].setRGB(0, 0, 0); leds[168].setRGB(0, 0, 0); leds[169].setRGB(0, 0, 0); leds[170].setRGB(0, 0, 0); leds[171].setRGB(0, 0, 0); leds[172].setRGB(0, 0, 0); leds[173].setRGB(0, 0, 0); leds[174].setRGB(0, 0, 0); leds[175].setRGB(0, 0, 0); leds[176].setRGB(0, 0, 0); leds[177].setRGB(0, 0, 0); leds[178].setRGB(0, 0, 0); leds[179].setRGB(0, 0, 0); leds[180].setRGB(0, 0, 0);
leds[181].setRGB(0, 0, 0); leds[182].setRGB(0, 0, 0); leds[183].setRGB(0, 0, 0); leds[184].setRGB(0, 0, 0); leds[185].setRGB(0, 0, 0); leds[186].setRGB(0, 0, 0); leds[187].setRGB(0, 0, 0); leds[188].setRGB(0, 0, 0); leds[189].setRGB(0, 0, 0); leds[190].setRGB(0, 0, 0); leds[191].setRGB(0, 0, 0); leds[192].setRGB(0, 0, 0); leds[193].setRGB(0, 0, 0); leds[194].setRGB(0, 0, 0); leds[195].setRGB(0, 0, 0); leds[196].setRGB(0, 0, 0); leds[197].setRGB(0, 0, 0); leds[198].setRGB(0, 0, 0); leds[199].setRGB(0, 0, 0); leds[200].setRGB(0, 0, 0); leds[201].setRGB(0, 0, 0); leds[202].setRGB(0, 0, 0); leds[203].setRGB(0, 0, 0); leds[204].setRGB(0, 0, 0); leds[205].setRGB(0, 0, 0); leds[206].setRGB(0, 0, 0); leds[207].setRGB(0, 0, 0); leds[208].setRGB(0, 0, 0); leds[209].setRGB(0, 0, 0); leds[210].setRGB(0, 0, 0);
leds[211].setRGB(0, 0, 0); leds[212].setRGB(0, 0, 0); leds[213].setRGB(0, 0, 0); leds[214].setRGB(0, 0, 0); leds[215].setRGB(0, 0, 0); leds[216].setRGB(0, 0, 0); leds[217].setRGB(0, 0, 0); leds[218].setRGB(0, 0, 0); leds[219].setRGB(0, 0, 0); leds[220].setRGB(0, 0, 0); leds[221].setRGB(0, 0, 0); leds[222].setRGB(0, 0, 0); leds[223].setRGB(0, 0, 0); leds[224].setRGB(0, 0, 0); leds[225].setRGB(0, 0, 0); leds[226].setRGB(0, 0, 0); leds[227].setRGB(0, 0, 0); leds[228].setRGB(0, 0, 0); leds[229].setRGB(0, 0, 0); leds[230].setRGB(0, 0, 0); leds[231].setRGB(0, 0, 0); leds[232].setRGB(0, 0, 0); leds[233].setRGB(0, 0, 0); leds[234].setRGB(0, 0, 0); leds[235].setRGB(0, 0, 0); leds[236].setRGB(0, 0, 0); leds[237].setRGB(0, 0, 0); leds[238].setRGB(0, 0, 0); leds[239].setRGB(0, 0, 0); leds[240].setRGB(0, 0, 0);
leds[241].setRGB(0, 0, 0); leds[242].setRGB(0, 0, 0); leds[243].setRGB(0, 0, 0); leds[244].setRGB(0, 0, 0); leds[245].setRGB(0, 0, 0); leds[246].setRGB(0, 0, 0); leds[247].setRGB(0, 0, 0); leds[248].setRGB(0, 0, 0); leds[249].setRGB(0, 0, 0); leds[250].setRGB(0, 0, 0); leds[251].setRGB(0, 0, 0); leds[252].setRGB(0, 0, 0); leds[253].setRGB(0, 0, 0); leds[254].setRGB(0, 0, 0); leds[255].setRGB(0, 0, 0); leds[256].setRGB(0, 0, 0); leds[257].setRGB(0, 0, 0); leds[258].setRGB(0, 0, 0); leds[259].setRGB(0, 0, 0); leds[260].setRGB(0, 0, 0); leds[261].setRGB(0, 0, 0); leds[262].setRGB(0, 0, 0); leds[263].setRGB(0, 0, 0); leds[264].setRGB(0, 0, 0); leds[265].setRGB(0, 0, 0); leds[266].setRGB(0, 0, 0); leds[267].setRGB(0, 0, 0); leds[268].setRGB(0, 0, 0); leds[269].setRGB(0, 0, 0); leds[270].setRGB(0, 0, 0);
leds[271].setRGB(0, 0, 0); leds[272].setRGB(0, 0, 0); leds[273].setRGB(0, 0, 0); leds[274].setRGB(0, 0, 0); leds[275].setRGB(0, 0, 0); leds[276].setRGB(0, 0, 0); leds[277].setRGB(0, 0, 0); leds[278].setRGB(0, 0, 0); leds[279].setRGB(0, 0, 0); leds[280].setRGB(0, 0, 0); leds[281].setRGB(0, 0, 0); leds[282].setRGB(0, 0, 0); leds[283].setRGB(0, 0, 0); leds[284].setRGB(0, 0, 0); leds[285].setRGB(0, 0, 0); leds[286].setRGB(0, 0, 0); leds[287].setRGB(0, 0, 0); leds[288].setRGB(0, 0, 0); leds[289].setRGB(0, 0, 0); leds[290].setRGB(0, 0, 0);
} void loop() { EVERY_N_MILLISECONDS(FRAME_DELAY) { frameIndex = nextFrameIndex(); fadeAmount = 0; }
EVERY_N_MILLISECONDS(FADE_DELAY) {
if(fadeAmount <255) fadeAmount++;
setColors();
FastLED.show();
}
}
void setColors() { switch (frameIndex) { case 0: leds[0].setRGB(0, 0, 0); leds[1].setRGB(0, 0, 0); leds[2].setRGB(0, 0, 0); leds[3].setRGB(0, 0, 0); leds[4].setRGB(0, 0, 0); leds[5].setRGB(0, 0, 0); leds[6].setRGB(0, 0, 0); leds[7].setRGB(0, 0, 0); leds[8].setRGB(0, 0, 0); leds[9].setRGB(0, 0, 0); leds[10].setRGB(0, 0, 0); leds[11].setRGB(0, 0, 0); leds[12].setRGB(0, 0, 0); leds[13].setRGB(0, 0, 0); leds[14].setRGB(0, 0, 0); leds[15].setRGB(0, 0, 0); leds[16].setRGB(0, 0, 0); leds[17].setRGB(0, 0, 0); leds[18].setRGB(0, 0, 0); leds[19].setRGB(0, 0, 0); leds[20].setRGB(0, 0, 0); leds[21].setRGB(0, 0, 0); leds[22].setRGB(0, 0, 0); leds[23].setRGB(0, 0, 0); leds[24].setRGB(0, 0, 0); leds[25].setRGB(0, 0, 0); leds[26].setRGB(0, 0, 0); leds[27].setRGB(0, 0, 0); leds[28].setRGB(0, 0, 0); leds[29].setRGB(0, 0, 0); leds[30].setRGB(0, 0, 0);
leds[31].setRGB(0, 0, 0); leds[32].setRGB(0, 0, 0); leds[33].setRGB(0, 0, 0); leds[34].setRGB(0, 0, 0); leds[35].setRGB(0, 0, 0); leds[36].setRGB(0, 0, 0); leds[37].setRGB(0, 0, 0); leds[38].setRGB(0, 0, 0); leds[39].setRGB(0, 0, 0); leds[40].setRGB(0, 0, 0); leds[41].setRGB(0, 0, 0); leds[42].setRGB(0, 0, 0); leds[43].setRGB(0, 0, 0); leds[44].setRGB(0, 0, 0); leds[45].setRGB(0, 0, 0); leds[46].setRGB(0, 0, 0); leds[47].setRGB(0, 0, 0); leds[48].setRGB(0, 0, 0); leds[49].setRGB(0, 0, 0); leds[50].setRGB(0, 0, 0); leds[51].setRGB(0, 0, 0); leds[52].setRGB(0, 0, 0); leds[53].setRGB(0, 0, 0); leds[54].setRGB(0, 0, 0); leds[55].setRGB(0, 0, 0); leds[56].setRGB(0, 0, 0); leds[57].setRGB(0, 0, 0); leds[58].setRGB(0, 0, 0); leds[59].setRGB(0, 0, 0); leds[60].setRGB(0, 0, 0);
leds[61].setRGB(0, 0, 0); leds[62].setRGB(0, 0, 0); leds[63].setRGB(0, 0, 0); leds[64].setRGB(0, 0, 0); leds[65].setRGB(0, 0, 0); leds[66].setRGB(0, 0, 0); leds[67].setRGB(0, 0, 0); leds[68].setRGB(0, 0, 0); leds[69].setRGB(0, 0, 0); leds[70].setRGB(0, 0, 0); leds[71].setRGB(0, 0, 0); leds[72].setRGB(0, 0, 0); leds[73].setRGB(0, 0, 0); leds[74].setRGB(0, 0, 0); leds[75].setRGB(0, 0, 0); leds[76].setRGB(0, 0, 0); leds[77].setRGB(0, 0, 0); leds[78].setRGB(0, 0, 0); leds[79].setRGB(0, 0, 0); leds[80].setRGB(0, 0, 0); leds[81].setRGB(0, 0, 0); leds[82].setRGB(0, 0, 0); leds[83].setRGB(0, 0, 0); leds[84].setRGB(0, 0, 0); leds[85].setRGB(0, 0, 0); leds[86].setRGB(0, 0, 0); leds[87].setRGB(0, 0, 0); leds[88].setRGB(0, 0, 0); leds[89].setRGB(0, 0, 0); leds[90].setRGB(0, 0, 0);
leds[91].setRGB(0, 0, 0); leds[92].setRGB(0, 0, 0); leds[93].setRGB(0, 0, 0); leds[94].setRGB(0, 0, 0); leds[95].setRGB(0, 0, 0); leds[96].setRGB(0, 0, 0); leds[97].setRGB(0, 0, 0); leds[98].setRGB(0, 0, 0); leds[99].setRGB(0, 0, 0); leds[100].setRGB(0, 0, 0); leds[101].setRGB(0, 0, 0); leds[102].setRGB(0, 0, 0); leds[103].setRGB(0, 0, 0); leds[104].setRGB(0, 0, 0); leds[105].setRGB(0, 0, 0); leds[106].setRGB(0, 0, 0); leds[107].setRGB(0, 0, 0); leds[108].setRGB(0, 0, 0); leds[109].setRGB(0, 0, 0); leds[110].setRGB(0, 0, 0); leds[111].setRGB(0, 0, 0); leds[112].setRGB(0, 0, 0); leds[113].setRGB(0, 0, 0); leds[114].setRGB(0, 0, 0); leds[115].setRGB(0, 0, 0); leds[116].setRGB(0, 0, 0); leds[117].setRGB(0, 0, 0); leds[118].setRGB(0, 0, 0); leds[119].setRGB(0, 0, 0); leds[120].setRGB(0, 0, 0);
leds[121].setRGB(0, 0, 0); leds[122].setRGB(0, 0, 0); leds[123].setRGB(0, 0, 0); leds[124].setRGB(0, 0, 0); leds[125].setRGB(0, 0, 0); leds[126].setRGB(0, 0, 0); leds[127].setRGB(0, 0, 0); leds[128].setRGB(0, 0, 0); leds[129].setRGB(0, 0, 0); leds[130].setRGB(0, 0, 0); leds[131].setRGB(0, 0, 0); leds[132].setRGB(0, 0, 0); leds[133].setRGB(0, 0, 0); leds[134].setRGB(0, 0, 0); leds[135].setRGB(0, 0, 0); leds[136].setRGB(0, 0, 0); leds[137].setRGB(0, 0, 0); leds[138].setRGB(0, 0, 0); leds[139].setRGB(0, 0, 0); leds[140].setRGB(0, 0, 0); leds[141].setRGB(0, 0, 0); leds[142].setRGB(0, 0, 0); leds[143].setRGB(0, 0, 0); leds[144].setRGB(0, 0, 0); leds[145].setRGB(0, 0, 0); leds[146].setRGB(0, 0, 0); leds[147].setRGB(0, 0, 0); leds[148].setRGB(0, 0, 0); leds[149].setRGB(0, 0, 0); leds[150].setRGB(0, 0, 0);
leds[151].setRGB(0, 0, 0); leds[152].setRGB(0, 0, 0); leds[153].setRGB(0, 0, 0); leds[154].setRGB(0, 0, 0); leds[155].setRGB(0, 0, 0); leds[156].setRGB(0, 0, 0); leds[157].setRGB(0, 0, 0); leds[158].setRGB(0, 0, 0); leds[159].setRGB(0, 0, 0); leds[160].setRGB(0, 0, 0); leds[161].setRGB(0, 0, 0); leds[162].setRGB(0, 0, 0); leds[163].setRGB(0, 0, 0); leds[164].setRGB(0, 0, 0); leds[165].setRGB(0, 0, 0); leds[166].setRGB(0, 0, 0); leds[167].setRGB(0, 0, 0); leds[168].setRGB(0, 0, 0); leds[169].setRGB(0, 0, 0); leds[170].setRGB(0, 0, 0); leds[171].setRGB(0, 0, 0); leds[172].setRGB(0, 0, 0); leds[173].setRGB(0, 0, 0); leds[174].setRGB(0, 0, 0); leds[175].setRGB(0, 0, 0); leds[176].setRGB(0, 0, 0); leds[177].setRGB(0, 0, 0); leds[178].setRGB(0, 0, 0); leds[179].setRGB(0, 0, 0); leds[180].setRGB(0, 0, 0);
leds[181].setRGB(0, 0, 0); leds[182].setRGB(0, 0, 0); leds[183].setRGB(0, 0, 0); leds[184].setRGB(0, 0, 0); leds[185].setRGB(0, 0, 0); leds[186].setRGB(0, 0, 0); leds[187].setRGB(0, 0, 0); leds[188].setRGB(0, 0, 0); leds[189].setRGB(0, 0, 0); leds[190].setRGB(0, 0, 0); leds[191].setRGB(0, 0, 0); leds[192].setRGB(0, 0, 0); leds[193].setRGB(0, 0, 0); leds[194].setRGB(0, 0, 0); leds[195].setRGB(0, 0, 0); leds[196].setRGB(0, 0, 0); leds[197].setRGB(0, 0, 0); leds[198].setRGB(0, 0, 0); leds[199].setRGB(0, 0, 0); leds[200].setRGB(0, 0, 0); leds[201].setRGB(0, 0, 0); leds[202].setRGB(0, 0, 0); leds[203].setRGB(0, 0, 0); leds[204].setRGB(0, 0, 0); leds[205].setRGB(0, 0, 0); leds[206].setRGB(0, 0, 0); leds[207].setRGB(0, 0, 0); leds[208].setRGB(0, 0, 0); leds[209].setRGB(0, 0, 0); leds[210].setRGB(0, 0, 0);
leds[211].setRGB(0, 0, 0); leds[212].setRGB(0, 0, 0); leds[213].setRGB(0, 0, 0); leds[214].setRGB(0, 0, 0); leds[215].setRGB(0, 0, 0); leds[216].setRGB(0, 0, 0); leds[217].setRGB(0, 0, 0); leds[218].setRGB(0, 0, 0); leds[219].setRGB(0, 0, 0); leds[220].setRGB(0, 0, 0); leds[221].setRGB(0, 0, 0); leds[222].setRGB(0, 0, 0); leds[223].setRGB(0, 0, 0); leds[224].setRGB(0, 0, 0); leds[225].setRGB(0, 0, 0); leds[226].setRGB(0, 0, 0); leds[227].setRGB(0, 0, 0); leds[228].setRGB(0, 0, 0); leds[229].setRGB(0, 0, 0); leds[230].setRGB(0, 0, 0); leds[231].setRGB(0, 0, 0); leds[232].setRGB(0, 0, 0); leds[233].setRGB(0, 0, 0); leds[234].setRGB(0, 0, 0); leds[235].setRGB(0, 0, 0); leds[236].setRGB(0, 0, 0); leds[237].setRGB(0, 0, 0); leds[238].setRGB(0, 0, 0); leds[239].setRGB(0, 0, 0); leds[240].setRGB(0, 0, 0);
leds[241].setRGB(0, 0, 0); leds[242].setRGB(0, 0, 0); leds[243].setRGB(0, 0, 0); leds[244].setRGB(0, 0, 0); leds[245].setRGB(0, 0, 0); leds[246].setRGB(0, 0, 0); leds[247].setRGB(0, 0, 0); leds[248].setRGB(0, 0, 0); leds[249].setRGB(0, 0, 0); leds[250].setRGB(0, 0, 0); leds[251].setRGB(0, 0, 0); leds[252].setRGB(0, 0, 0); leds[253].setRGB(0, 0, 0); leds[254].setRGB(0, 0, 0); leds[255].setRGB(0, 0, 0); leds[256].setRGB(0, 0, 0); leds[257].setRGB(0, 0, 0); leds[258].setRGB(0, 0, 0); leds[259].setRGB(0, 0, 0); leds[260].setRGB(0, 0, 0); leds[261].setRGB(0, 0, 0); leds[262].setRGB(0, 0, 0); leds[263].setRGB(255, 255, 255); /// leds[264].setRGB(255, 255, 255); leds[265].setRGB(255, 255, 255); leds[266].setRGB(255, 255, 255); leds[267].setRGB(255, 255, 255); leds[268].setRGB(255, 255, 255); leds[269].setRGB(255, 255, 255); leds[270].setRGB(255, 255, 255);
leds[271].setRGB(255, 255, 255); leds[272].setRGB(255, 255, 255); leds[273].setRGB(255, 255, 255); leds[274].setRGB(255, 255, 255); leds[275].setRGB(255, 255, 255); leds[276].setRGB(255, 255, 255); leds[277].setRGB(255, 255, 255); leds[278].setRGB(255, 255, 255); leds[279].setRGB(255, 255, 255); leds[280].setRGB(255, 255, 255); leds[281].setRGB(255, 255, 255); leds[282].setRGB(255, 255, 255); leds[283].setRGB(255, 255, 255); leds[284].setRGB(255, 255, 255); leds[285].setRGB(255, 255, 255); leds[286].setRGB(255, 255, 255); leds[287].setRGB(255, 255, 255); leds[288].setRGB(255, 255, 255); leds[289].setRGB(255, 255, 255); leds[290].setRGB(255, 255, 255); break;
//////////////////// 43 cm/chip
case 1: leds[0].setRGB(255, 255, 255); break; case 2: leds[1].setRGB(255, 255, 255); break; case 3 : leds[2].setRGB(255, 255, 255); break; case 4 : leds[3].setRGB(255, 255, 255); break; case 5: leds[4].setRGB(255, 255, 255); break; case 6: leds[5].setRGB(255, 255, 255); break; case 7: leds[6].setRGB(255, 255, 255); break; case 8: leds[7].setRGB(255, 255, 255); break; case 9: leds[8].setRGB(255, 255, 255); break; case 10: leds[9].setRGB(255, 255, 255); break; case 11: leds[10].setRGB(255, 255, 255); break; case 12: leds[11].setRGB(255, 255, 255); break; case 13: leds[12].setRGB(255, 255, 255); break; case 14: leds[13].setRGB(255, 255, 255); break; case 15: leds[14].setRGB(255, 255, 255); break; case 16: leds[15].setRGB(255, 255, 255); break; case 17: leds[16].setRGB(255, 255, 255); break; case 18: leds[17].setRGB(255, 255, 255); break; case 19: leds[18].setRGB(255, 255, 255); break; case 20: leds[19].setRGB(255, 255, 255); break; case 21: leds[20].setRGB(255, 255, 255); break; case 22: leds[21].setRGB(255, 255, 255); break; case 23: leds[22].setRGB(255, 255, 255); break; case 24: leds[23].setRGB(255, 255, 255); break; case 25: leds[24].setRGB(255, 255, 255); break; case 26: leds[25].setRGB(255, 255, 255); break; case 27: leds[26].setRGB(255, 255, 255); break; case 28: leds[27].setRGB(255, 255, 255); break; case 29: leds[28].setRGB(255, 255, 255); break; case 30: leds[29].setRGB(255, 255, 255); break; case 31: leds[30].setRGB(255, 255, 255); break; case 32: leds[31].setRGB(255, 255, 255); break; case 33: leds[32].setRGB(255, 255, 255); break; case 34: leds[33].setRGB(255, 255, 255); break; case 35: leds[34].setRGB(255, 255, 255); break; case 36: leds[35].setRGB(255, 255, 255); break; case 37: leds[36].setRGB(255, 255, 255); break; case 38: leds[37].setRGB(255, 255, 255); break; case 39: leds[38].setRGB(255, 255, 255); break; case 40: leds[39].setRGB(255, 255, 255); break; case 41: leds[40].setRGB(255, 255, 255); break; case 42: leds[41].setRGB(255, 255, 255); break; case 43: leds[42].setRGB(255, 255, 255); break;
//////////////////// 20cm/chip
case 44: leds[43].setRGB(255, 255, 255); break; case 45: leds[44].setRGB(255, 255, 255); break; case 46: leds[45].setRGB(255, 255, 255); break; case 47: leds[46].setRGB(255, 255, 255); break; case 48: leds[47].setRGB(255, 255, 255); break; case 49: leds[48].setRGB(255, 255, 255); break; case 50: leds[49].setRGB(255, 255, 255); break; case 51: leds[50].setRGB(255, 255, 255); break; case 52: leds[51].setRGB(255, 255, 255); break; case 53: leds[52].setRGB(255, 255, 255); break; case 54: leds[53].setRGB(255, 255, 255); break; case 55: leds[54].setRGB(255, 255, 255); break; case 56: leds[55].setRGB(255, 255, 255); break; case 57: leds[56].setRGB(255, 255, 255); break; case 58: leds[57].setRGB(255, 255, 255); break; case 59: leds[58].setRGB(255, 255, 255); break; case 60: leds[59].setRGB(255, 255, 255); break; case 61: leds[60].setRGB(255, 255, 255); break; case 62: leds[61].setRGB(255, 255, 255); break; case 63: leds[62].setRGB(255, 255, 255); break;
//////////////////// 15 cm/chip
case 64: leds[63].setRGB(255, 255, 255);leds[63].nscale8(fadeAmount); leds[64].setRGB(255, 255, 255);leds[64].nscale8(fadeAmount); leds[65].setRGB(255, 255, 255);leds[65].nscale8(fadeAmount); leds[66].setRGB(255, 255, 255);leds[66].nscale8(fadeAmount); leds[67].setRGB(255, 255, 255);leds[67].nscale8(fadeAmount); leds[68].setRGB(255, 255, 255);leds[68].nscale8(fadeAmount); leds[69].setRGB(255, 255, 255);leds[69].nscale8(fadeAmount); leds[70].setRGB(255, 255, 255);leds[70].nscale8(fadeAmount); leds[71].setRGB(255, 255, 255);leds[71].nscale8(fadeAmount); leds[72].setRGB(255, 255, 255);leds[72].nscale8(fadeAmount); leds[73].setRGB(255, 255, 255);leds[73].nscale8(fadeAmount); leds[74].setRGB(255, 255, 255);leds[74].nscale8(fadeAmount); leds[75].setRGB(255, 255, 255);leds[75].nscale8(fadeAmount); leds[76].setRGB(255, 255, 255);leds[76].nscale8(fadeAmount); leds[77].setRGB(255, 255, 255);leds[77].nscale8(fadeAmount); break;
//////////////////// 12 cm/chip
case 65: leds[78].setRGB(255, 255, 255);leds[78].nscale8(fadeAmount); leds[79].setRGB(255, 255, 255);leds[79].nscale8(fadeAmount); leds[80].setRGB(255, 255, 255);leds[80].nscale8(fadeAmount); leds[81].setRGB(255, 255, 255);leds[81].nscale8(fadeAmount); leds[82].setRGB(255, 255, 255);leds[82].nscale8(fadeAmount); leds[83].setRGB(255, 255, 255);leds[83].nscale8(fadeAmount); leds[84].setRGB(255, 255, 255);leds[84].nscale8(fadeAmount); leds[85].setRGB(255, 255, 255);leds[85].nscale8(fadeAmount); leds[86].setRGB(255, 255, 255);leds[86].nscale8(fadeAmount); leds[87].setRGB(255, 255, 255);leds[87].nscale8(fadeAmount); leds[88].setRGB(255, 255, 255);leds[88].nscale8(fadeAmount); leds[89].setRGB(255, 255, 255);leds[89].nscale8(fadeAmount); break;
//////////////////// 18 cm/chip
case 66: leds[90].setRGB(255, 255, 255);leds[90].nscale8(fadeAmount); leds[91].setRGB(255, 255, 255);leds[91].nscale8(fadeAmount); leds[92].setRGB(255, 255, 255);leds[92].nscale8(fadeAmount); leds[93].setRGB(255, 255, 255);leds[93].nscale8(fadeAmount); leds[94].setRGB(255, 255, 255);leds[94].nscale8(fadeAmount); leds[95].setRGB(255, 255, 255);leds[95].nscale8(fadeAmount); leds[96].setRGB(255, 255, 255);leds[96].nscale8(fadeAmount); leds[97].setRGB(255, 255, 255);leds[97].nscale8(fadeAmount); leds[98].setRGB(255, 255, 255);leds[98].nscale8(fadeAmount); leds[99].setRGB(255, 255, 255);leds[99].nscale8(fadeAmount); leds[100].setRGB(255, 255, 255);leds[100].nscale8(fadeAmount); leds[101].setRGB(255, 255, 255);leds[101].nscale8(fadeAmount); leds[102].setRGB(255, 255, 255);leds[102].nscale8(fadeAmount); leds[103].setRGB(255, 255, 255);leds[103].nscale8(fadeAmount); leds[104].setRGB(255, 255, 255);leds[104].nscale8(fadeAmount); leds[105].setRGB(255, 255, 255);leds[105].nscale8(fadeAmount); leds[106].setRGB(255, 255, 255);leds[106].nscale8(fadeAmount); leds[107].setRGB(255, 255, 255);leds[107].nscale8(fadeAmount); break;
//////////////////// 13 cm/chip
case 67: leds[108].setRGB(255, 255, 255);leds[108].nscale8(fadeAmount); leds[109].setRGB(255, 255, 255);leds[109].nscale8(fadeAmount); leds[110].setRGB(255, 255, 255);leds[110].nscale8(fadeAmount); leds[111].setRGB(255, 255, 255);leds[111].nscale8(fadeAmount); leds[112].setRGB(255, 255, 255);leds[112].nscale8(fadeAmount); leds[113].setRGB(255, 255, 255);leds[113].nscale8(fadeAmount); leds[114].setRGB(255, 255, 255);leds[114].nscale8(fadeAmount); leds[115].setRGB(255, 255, 255);leds[115].nscale8(fadeAmount); leds[116].setRGB(255, 255, 255);leds[116].nscale8(fadeAmount); leds[117].setRGB(255, 255, 255);leds[117].nscale8(fadeAmount); leds[118].setRGB(255, 255, 255);leds[118].nscale8(fadeAmount); leds[119].setRGB(255, 255, 255);leds[119].nscale8(fadeAmount); leds[120].setRGB(255, 255, 255);leds[120].nscale8(fadeAmount); break;
//////////////////// 20 cm/chip
case 68: leds[121].setRGB(255, 255, 255); break; case 69: leds[122].setRGB(255, 255, 255); break; case 70: leds[123].setRGB(255, 255, 255); break; case 71: leds[124].setRGB(255, 255, 255); break; case 72: leds[125].setRGB(255, 255, 255); break; case 73: leds[126].setRGB(255, 255, 255); break; case 74: leds[127].setRGB(255, 255, 255); break; case 75: leds[128].setRGB(255, 255, 255); break; case 76: leds[129].setRGB(255, 255, 255); break; case 77: leds[130].setRGB(255, 255, 255); break; case 78: leds[131].setRGB(255, 255, 255); break; case 79: leds[132].setRGB(255, 255, 255); break; case 80: leds[133].setRGB(255, 255, 255); break; case 81: leds[134].setRGB(255, 255, 255); break; case 82: leds[135].setRGB(255, 255, 255); break; case 83: leds[136].setRGB(255, 255, 255); break; case 84: leds[137].setRGB(255, 255, 255); break; case 85: leds[138].setRGB(255, 255, 255); break; case 86: leds[139].setRGB(255, 255, 255); break; case 87: leds[140].setRGB(255, 255, 255); break;
//////////////////// 52 cm/chip
case 88: leds[141].setRGB(255, 255, 255); break; case 89 : leds[142].setRGB(255, 255, 255); break; case 90: leds[143].setRGB(255, 255, 255); break; case 91: leds[144].setRGB(255, 255, 255); break; case 92: leds[145].setRGB(255, 255, 255); break; case 93: leds[146].setRGB(255, 255, 255); break; case 94: leds[147].setRGB(255, 255, 255); break; case 95: leds[148].setRGB(255, 255, 255); break; case 96: leds[149].setRGB(255, 255, 255); break; case 97: leds[150].setRGB(255, 255, 255); break; case 98: leds[151].setRGB(255, 255, 255); break; case 99: leds[152].setRGB(255, 255, 255); break; case 100: leds[153].setRGB(255, 255, 255); break; case 101: leds[154].setRGB(255, 255, 255); break; case 102: leds[155].setRGB(255, 255, 255); break; case 103: leds[156].setRGB(255, 255, 255); break; case 104: leds[157].setRGB(255, 255, 255); break; case 105: leds[158].setRGB(255, 255, 255); break; case 106: leds[159].setRGB(255, 255, 255); break; case 107: leds[160].setRGB(255, 255, 255); break; case 108: leds[161].setRGB(255, 255, 255); break; case 109: leds[162].setRGB(255, 255, 255); break; case 110: leds[163].setRGB(255, 255, 255); break; case 111: leds[164].setRGB(255, 255, 255); break; case 112: leds[165].setRGB(255, 255, 255); break; case 113: leds[166].setRGB(255, 255, 255); break; case 114: leds[167].setRGB(255, 255, 255); break; case 115: leds[168].setRGB(255, 255, 255); break; case 116: leds[169].setRGB(255, 255, 255); break; case 117: leds[170].setRGB(255, 255, 255); break; case 118: leds[171].setRGB(255, 255, 255); break; case 119: leds[172].setRGB(255, 255, 255); break; case 120: leds[173].setRGB(255, 255, 255); break; case 121: leds[174].setRGB(255, 255, 255); break; case 122: leds[175].setRGB(255, 255, 255); break; case 123: leds[176].setRGB(255, 255, 255); break; case 124: leds[177].setRGB(255, 255, 255); break; case 125: leds[178].setRGB(255, 255, 255); break; case 126: leds[179].setRGB(255, 255, 255); break; case 127: leds[180].setRGB(255, 255, 255); break; case 128: leds[181].setRGB(255, 255, 255); break; case 129: leds[182].setRGB(255, 255, 255); break; case 130: leds[183].setRGB(255, 255, 255); break; case 131: leds[184].setRGB(255, 255, 255); break; case 132: leds[185].setRGB(255, 255, 255); break; case 133: leds[186].setRGB(255, 255, 255); break; case 134: leds[187].setRGB(255, 255, 255); break; case 135: leds[188].setRGB(255, 255, 255); break; case 136: leds[189].setRGB(255, 255, 255); break; case 137: leds[190].setRGB(255, 255, 255); break; case 138: leds[191].setRGB(255, 255, 255); break; case 139: leds[192].setRGB(255, 255, 255); break;
//////////////////// 19 cm/chip
case 140: leds[193].setRGB(255, 255, 255); break; case 141: leds[194].setRGB(255, 255, 255); break; case 142: leds[195].setRGB(255, 255, 255); break; case 143: leds[196].setRGB(255, 255, 255); break; case 144: leds[197].setRGB(255, 255, 255); break; case 145: leds[198].setRGB(255, 255, 255); break; case 146: leds[199].setRGB(255, 255, 255); break; case 147: leds[200].setRGB(255, 255, 255); break; case 148: leds[201].setRGB(255, 255, 255); break; case 149: leds[202].setRGB(255, 255, 255); break; case 150: leds[203].setRGB(255, 255, 255); break; case 151: leds[204].setRGB(255, 255, 255); break; case 152: leds[205].setRGB(255, 255, 255); break; case 153: leds[206].setRGB(255, 255, 255); break; case 154: leds[207].setRGB(255, 255, 255); break; case 155: leds[208].setRGB(255, 255, 255); break; case 156: leds[209].setRGB(255, 255, 255); break; case 157: leds[210].setRGB(255, 255, 255); break; case 158: leds[211].setRGB(255, 255, 255); break;
//////////////////// 51 cm/chip
case 159: leds[212].setRGB(255, 255, 255); break; case 160: leds[213].setRGB(255, 255, 255); break; case 161: leds[214].setRGB(255, 255, 255); break; case 162: leds[215].setRGB(255, 255, 255); break; case 163: leds[216].setRGB(255, 255, 255); break; case 164: leds[217].setRGB(255, 255, 255); break; case 165: leds[218].setRGB(255, 255, 255); break; case 166: leds[219].setRGB(255, 255, 255); break; case 167: leds[220].setRGB(255, 255, 255); break; case 168: leds[221].setRGB(255, 255, 255); break; case 169: leds[223].setRGB(255, 255, 255); break; case 170: leds[224].setRGB(255, 255, 255); break; case 171: leds[226].setRGB(255, 255, 255); break; case 172: leds[227].setRGB(255, 255, 255); break; case 173: leds[228].setRGB(255, 255, 255); break; case 174: leds[229].setRGB(255, 255, 255); break; case 175: leds[230].setRGB(255, 255, 255); break; case 176: leds[231].setRGB(255, 255, 255); break; case 177: leds[232].setRGB(255, 255, 255); break; case 178: leds[233].setRGB(255, 255, 255); break; case 179: leds[234].setRGB(255, 255, 255); break; case 180: leds[235].setRGB(255, 255, 255); break; case 181: leds[236].setRGB(255, 255, 255); break; case 182: leds[237].setRGB(255, 255, 255); break; case 183: leds[238].setRGB(255, 255, 255); break; case 184: leds[239].setRGB(255, 255, 255); break; case 185: leds[240].setRGB(255, 255, 255); break; case 186: leds[241].setRGB(255, 255, 255); break; case 187: leds[242].setRGB(255, 255, 255); break; case 188: leds[243].setRGB(255, 255, 255); break; case 189: leds[244].setRGB(255, 255, 255); break; case 190: leds[245].setRGB(255, 255, 255); break; case 191: leds[246].setRGB(255, 255, 255); break; case 192: leds[247].setRGB(255, 255, 255); break; case 193: leds[248].setRGB(255, 255, 255); break; case 194: leds[249].setRGB(255, 255, 255); break; case 195: leds[250].setRGB(255, 255, 255); break; case 196: leds[251].setRGB(255, 255, 255); break; case 197: leds[252].setRGB(255, 255, 255); break; case 198: leds[253].setRGB(255, 255, 255); break; case 199: leds[254].setRGB(255, 255, 255); break; case 200: leds[255].setRGB(255, 255, 255); break; case 201: leds[256].setRGB(255, 255, 255); break; case 202: leds[257].setRGB(255, 255, 255); break; case 203: leds[258].setRGB(255, 255, 255); break; case 204: leds[259].setRGB(255, 255, 255); break; case 205: leds[260].setRGB(255, 255, 255); break; case 206: leds[261].setRGB(255, 255, 255); break; case 207: leds[262].setRGB(255, 255, 255); break;
}
}
I tried the one without the pot
I tried 300 pixels 1 roll, ws2812b 5 volt
First off, if you're using WS2812B LEDs, you should change your addLeds statement to reflect that:
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
As for the dimming issue you're having, it's because the number of LEDs you're trying to drive (300!) slows down the fade function. Updating each LED takes 30 microseconds, so updating 300 takes 9 milliseconds. That's just too long and is causing the fade-in function to end prematurely and leave the LEDs in a dimmed state. I think the easiest solution is to introduce another constant that determines the amount of "fade" that is applied each time the show() is executed (and is a function of the number of LEDs being driven). I came up with this:
#define FRAME_DELAY 512 // should a power of 2
#define FADE_STEP ((NUM_LEDS / 32) + 1)
#define FADE_DELAY (FRAME_DELAY / (256 / FADE_STEP))
And the EVERY_N_MILLISECONDS(FADE_DELAY) loop changes to this:
EVERY_N_MILLISECONDS(FADE_DELAY) {
if (fadeAmount < (255 - FADE_STEP)) fadeAmount+=FADE_STEP;
setColors();
FastLED.show();
}
That seemed to work better in my limited testing. Give it a try.
I'll also mention that 300 LEDs is A LOT! It's not uncommon for a single WS2812B to draw 40-50mA when set to WHITE at full brightness. 300 WS2812Bs would draw over 12 Amps! This is not trivial and can be dangerous. You should definitely read the Neopixel Uberguide especially the section on power requirements and power distribution.
for my power is not a problem, I understand. . I will try your sketch later.
sorry I want to ask, can my small project run using the WS2812FX format?
WS2812FX ws2812fx = WS2812FX(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
void setup() { Serial.begin(115200);
ws2812fx.init(); ws2812fx.setBrightness(255);
ws2812fx.start(); }
void loop() { ws2812fx.setSegment(0, 0, 62, 30, WHITE, 1000, false); ws2812fx.setSegment(1, 63, 78 , 15, WHITE, 500, false); ws2812fx.setSegment(2, 63, 78 , 15, WHITE, 500, false); ws2812fx.setSegment(3, 79, 90 , 15, WHITE, 500, false); ws2812fx.setSegment(4, 91, 108 , 15, WHITE, 500, false); ws2812fx.setSegment(5, 109, 121 , 15, WHITE, 500, false); ws2812fx.setSegment(6, 121, 263 , 30, WHITE, 500, false); ws2812fx.setSegment(7, 264, 290 , 0, WHITE, 1000, false);
ws2812fx.service(); }
I tried to make it like this but, no looping, the results run concurrently not sequentially for each segment.
hahahaha
Yeah, unfortunately WS2812FX doesn't have a good API to manipulate LEDs sequentially. FastLED's EVERY_N_MILLISECONDS() feature makes it a little easier, but it's still not straightforward. Actually, for this type of application I don't think you need anything more than the basic Adafruit_NeoPixel library.
This is a test sketch I made, starting from your sketch and modifying it to use Adafruit_Neopixel:
#include <Adafruit_NeoPixel.h>
#define NUM_LEDS 290
#define DATA_PIN 2
#define MAX_FRAMES 207
#define FRAME_DELAY 512 // should a power of 2
#define FADE_STEP ((NUM_LEDS / 32) + 1)
#define FADE_DELAY (FRAME_DELAY / (256 / FADE_STEP))
Adafruit_NeoPixel leds(NUM_LEDS, DATA_PIN, NEO_GRB + NEO_KHZ800);
int frameIndex = 0;
int fadeAmount = 0;
uint32_t color = leds.Color(0, 255, 0); // foreground color (green)
uint32_t bgColor = leds.Color(0, 0, 0); // background color (black)
int nextFrameIndex() {
if (frameIndex < MAX_FRAMES - 1) {
return frameIndex + 1;
} else {
return 0;
}
}
void fill(int start, int end, uint32_t color) {
leds.fill(color, start, end - start + 1);
}
void fillFade(int start, int end, uint32_t color) {
uint8_t r = (color >> 16) * fadeAmount / 256;
uint8_t g = ((color >> 8) & 0xff) * fadeAmount / 256;
uint8_t b = (color & 0xff) * fadeAmount / 256;
uint32_t fadedColor = leds.Color(r, g, b);
leds.fill(fadedColor, start, end - start + 1);
}
void setup() {
leds.begin();
leds.setBrightness(255);
// Frame 1
leds.clear();
leds.show();
}
void loop() {
static uint64_t frameTimer = 0, fadeTimer = 0;
uint64_t now = millis();
if(now > frameTimer + FRAME_DELAY) { // EVERY_N_MILLISECONDS(FRAME_DELAY)
frameIndex = nextFrameIndex();
fadeAmount = 0;
frameTimer = now;
}
if(now > fadeTimer + FADE_DELAY) { // EVERY_N_MILLISECONDS(FADE_DELAY)
if (fadeAmount < (255 - FADE_STEP)) fadeAmount+=FADE_STEP;
setColors();
leds.show();
fadeTimer = now;
}
}
void setColors() {
switch (frameIndex) {
case 0:
fill( 0, 262, bgColor); // leds[0] - leds[262]
fill(263, 290, color); // leds[263] - leds[290]
break;
//////////////////// 43 cm/chip
case 1 ... 63:
leds.setPixelColor(frameIndex - 1, color); // leds[0] - leds[62]
break;
//////////////////// 15 cm/chip
case 64:
fillFade(63, 77, color); // leds[63] - leds[77]
break;
//////////////////// 12 cm/chip
case 65:
fillFade(78, 89, color); // leds[78] - leds[89]
break;
//////////////////// 18 cm/chip
case 66:
fillFade(90, 107, color); // leds[90] - leds[107]
break;
//////////////////// 13 cm/chip
case 67:
fillFade(108, 120, color); // leds[108] - leds[120]
break;
//////////////////// 20 cm/chip
case 68 ... 207:
leds.setPixelColor(frameIndex - 68 + 121, color); // leds[121] - leds[260]
break;
}
}
the animation is good, but if I change the frame_delay speed, the fade animation becomes fast too, how do I make the fade animation smooth, and between cases the fade has a delay,
The code tries to complete the fade before the next frame starts, so if you reduce FRAME_RATE to make the animation run faster it has to make the fade run faster too. I'm not sure how to get around that. You could have more than one fadeAmount variable and time the fade separately for each frame, and maybe have the fades overlap, but that would get quite complicated.
Not sure what you mean by "make the fade animation smooth". The large number of LEDs in your setup puts constraints on how fast the fades can run and what fraction of brightness gets applied for each fade step. The fades would run smoother if you reduced the number of LEDs, if that's an option.
Also "between cases the fade has a delay" is confusing to me. Do you want to start the fade a short time after the case statement is reached? I think that would make the fade smoothness worse.
the delay I mean is the delay in , case 64- case 67. but I have tried that by adding the delay line and running. only the smoothness of the fadding has not been found, I have tried various methods from the internet but the fade function still doesn't work.
I'm still not clear on what your goal is. My test bench only has 128 LEDs, so I can't test with a complete strip of 300 LEDs, but what I have seems to be working. The middle sections of LEDs fade-in as I expect them to. Maybe you could send your sketch or let me know what changes you've made, and I can investigate further.
Adafruit_NeoPixel leds(NUM_LEDS, DATA_PIN, NEO_GRB + NEO_KHZ800);
int frameIndex = 0; int fadeAmount = 0;
uint32_t color = leds.Color(255, 255, 255); // foreground color (green) uint32_t bgColor = leds.Color(0, 0, 0); // background color (black)
int nextFrameIndex() { if (frameIndex < MAX_FRAMES - 1) { return frameIndex + 1; } else { return 0; } }
void fill(int start, int end, uint32_t color) { leds.fill(color, start, end - start + 1); }
void fillFade(int start, int end, uint32_t color) { uint8_t r = (color >> 16) fadeAmount / 256; uint8_t g = ((color >> 8) & 0xff) fadeAmount / 256; uint8_t b = (color & 0xff) * fadeAmount / 256; uint32_t fadedColor = leds.Color(r, g, b); leds.fill(fadedColor, start, end - start + 1); }
void setup() { leds.begin(); leds.setBrightness(255);
// Frame 1 leds.clear(); leds.show(); }
void loop() { static uint64_t frameTimer = 0, fadeTimer = 0; uint64_t now = millis();
if(now > frameTimer + FRAME_DELAY) { // EVERY_N_MILLISECONDS(FRAME_DELAY) frameIndex = nextFrameIndex(); fadeAmount = 0; frameTimer = now; }
if(now > fadeTimer + FADE_DELAY) { // EVERY_N_MILLISECONDS(FADE_DELAY) if (fadeAmount < (256 - FADE_STEP)) fadeAmount=-FADE_STEP; setColors(); leds.show(); fadeTimer = 0; } }
void setColors() { switch (frameIndex) { case 0: fill( 0, 262, bgColor); // leds[0] - leds[262] fill(263, 290, color); // leds[263] - leds[290] break;
//////////////////// 43 cm/chip
case 1 ... 63:
leds.setPixelColor(frameIndex - 1, color); // leds[0] - leds[62]
break;
//////////////////// 15 cm/chip
case 64:
fillFade(63, 77, color); // leds[63] - leds[77]
break;
//////////////////// 12 cm/chip
case 65:
fillFade(78, 89, color); // leds[78] - leds[89]
delay(1000);
//////////////////// 18 cm/chip
case 66:
fillFade(90, 108, color); // leds[90] - leds[107]
leds.show();
delay(500);
//////////////////// 13 cm/chip
fillFade(109, 121, color); // leds[108] - leds[120]
delay(1000);
//////////////////// 20 cm/chip
case 68 ... 207:
leds.setPixelColor(frameIndex - 68 + 123, color); // leds[121] - leds[260]
break;
} }
I only made a few changes, what I haven't been able to get is the fading effect which isn't perfect yet.
You've set FRAME_DELAY = 10ms, but you can't possibly fade-in the LEDs in 10ms. It sounds like you want two different frame rates. A fast frame rate when you're turning on one LED at a time (for case 1 ... 63), and a slow frame rate when you're fading in groups of LEDs (for case 64 ... 67). You want the program to linger for case 64 ... 67, so you can implement a slow fade. Does that sound right?
yes right
in case 64 to 67, still on pause as I did there is a delay of 1000 ms.
according to the way it works, what I'm making, the led runs from case 1 to case 63, then when case 64 lights up it fades then moves to the next case. and back again running on case 68..
OK, I see what you're after. I added a setFadeTime() function to set the fade time independent of the frame delay. It's messy, but I think it will do the job.
Note, the timing is not very accurate. With long strips of LEDs, disabling interrupts (which happens when the LEDs are being updated) causes problems with the millis() function. For example, in my new sketch I use setFadeTime(3000);
to try to get a 3 second fade, but when I run the sketch the fade actually lasts about 4.5 seconds. So you'll need to play with the 'fadeTime' parameter a bit if you want to get accurate fade times.
#include <Adafruit_NeoPixel.h>
#define NUM_LEDS 290
#define DATA_PIN 2
#define MAX_FRAMES 207
#define LED_UPDATE_TIME (((NUM_LEDS * 30) + 300) / 1000) // time it takes to update the strip of LEDs in milliseconds
#define FRAME_DELAY 20 // default frame delay in milliseconds
int frameIndex = -1;
int frameDelay = FRAME_DELAY; // frameDelay in milliseconds
int fadeDelay = 0; // fadeDelay in milliseconds (set to 0 to disable fade)
int fadeStep = 1;
int fadeAmount = 0;
Adafruit_NeoPixel leds(NUM_LEDS, DATA_PIN, NEO_GRB + NEO_KHZ800);
uint32_t color = leds.Color(0, 255, 0); // foreground color (green)
uint32_t bgColor = leds.Color(0, 0, 0); // background color (black)
void nextFrame() {
frameIndex++;
if(frameIndex > MAX_FRAMES) frameIndex = 0;
}
void fill(int start, int end, uint32_t color) {
leds.fill(color, start, end - start + 1);
}
void fillFade(int start, int end, uint32_t color) {
uint8_t r = (color >> 16) * fadeAmount / 256;
uint8_t g = ((color >> 8) & 0xff) * fadeAmount / 256;
uint8_t b = (color & 0xff) * fadeAmount / 256;
uint32_t fadedColor = leds.Color(r, g, b);
leds.fill(fadedColor, start, end - start + 1);
}
void setFadeTime(int fadeTime) { // set fade time in milliseconds
if(fadeTime) {
if(fadeTime / 256 > LED_UPDATE_TIME) { // if LED update time is less...
fadeDelay = fadeTime / 256;
fadeStep = 1;
} else {
int numSteps = fadeTime / LED_UPDATE_TIME;
fadeDelay = LED_UPDATE_TIME;
fadeStep = 256 / numSteps;
}
frameDelay = fadeTime;
} else {
frameDelay = FRAME_DELAY;
}
}
void setup() {
leds.begin();
leds.setBrightness(64);
// Frame 1
leds.clear();
leds.show();
}
void loop() {
static uint64_t frameTimer = 0, fadeTimer = 0;
uint64_t now = millis();
if(now > frameTimer + frameDelay) {
nextFrame();
fadeAmount = 0;
if(!fadeDelay) { // if not fading, update LEDs immediately
setColors();
leds.show();
}
frameTimer = now;
}
if(fadeDelay && now > fadeTimer + fadeDelay) { // if fading, calc intermediate frames
fadeAmount+=fadeStep;
if (fadeAmount > 255) fadeAmount = 255;
setColors();
leds.show();
fadeTimer = now;
}
}
void setColors() {
switch (frameIndex) {
case 0:
fill( 0, 262, bgColor); // leds[0] - leds[262]
fill(263, 290, color); // leds[263] - leds[290]
setFadeTime(0); // disable fade
break;
//////////////////// 43 cm/chip
case 1 ... 63:
leds.setPixelColor(frameIndex - 1, color); // leds[0] - leds[62]
setFadeTime(0); // disable fade
break;
//////////////////// 15 cm/chip
case 64:
fillFade(63, 77, color); // leds[63] - leds[77]
setFadeTime(3000); // set fade time in milliseconds
break;
//////////////////// 12 cm/chip
case 65:
fillFade(78, 89, color); // leds[78] - leds[89]
setFadeTime(3000); // set fade time in milliseconds
break;
//////////////////// 18 cm/chip
case 66:
fillFade(90, 107, color); // leds[90] - leds[107]
setFadeTime(3000); // set fade time in milliseconds
break;
//////////////////// 13 cm/chip
case 67:
fillFade(108, 120, color); // leds[108] - leds[120]
setFadeTime(3000); // set fade time in milliseconds
break;
//////////////////// 20 cm/chip
case 68 ... 207:
leds.setPixelColor(frameIndex - 68 + 121, color); // leds[121] - leds[260]
setFadeTime(0); // disable fade
break;
}
}
sorry to bother you, haven't visited you for a long time, this time I want to ask all my friends, I want to ask how to add potentio function to ws2812bfx, thank you all