You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm running an ws2812b LED strip containing 49 LEDS, power comes from a 5V/3A PSU, all driven by an Arduino UNO.
This is a test setup for a big installation I'm doing running bigger strips.
The thing is, I'm trying to do a "running light" effect, I need a group of leds turned on in a desired color "moving" along the strip, over and over again, should be easy.
After looking at the examples I came with this, I'm not a coding guy, the sketch is quite simple, but functional:
#include <FastLED.h>
#define LED_PIN 7
//#define CLOCK_PIN 4
#define NUM_LEDS 49
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
#define BRIGHTNESS 255
CRGB leds[NUM_LEDS];
void setup() {
delay(5000);
//Tiempo desde encendido a comienzo de patrón//
LEDS.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS);
// LEDS.addLeds<LED_TYPE, LED_PIN, CLOCK_PIN COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);
}
void loop()
{
FastLED.clear();
for(int i=0;i<NUM_LEDS;i++){
leds[i-7].setRGB(0,0,0);
leds[i].setRGB(255,50,10);
FastLED.show();
delay(100);
//Tiempo, en milisegundos, de encendido del siguiente LED//
}
FastLED.clear();
}
The problem comes when I try to make bigger the running line by increasing the number in this line:
leds[i-7].setRGB(0,0,0);
As soon as I get it bigger than 7, the speed drops dramatically and I'm not able to control it by changing any delay number, with i-8 it still runs, quite slow, but bigger than that it just doesn't run, even compiling nicely with no warnings or whatever.
This looks just wrong. "i" goes from 0 to NUM_LEDS-1. So you will end up with indexes for leds[] starting with -7. However, an index can't be less than 0. It does not magically wrap around to the end of the array (though, I admit, that would be a handy feature). I'm surprised this runs at all...
One way to solve it is to track the end of the 7 lit LEDs separately. Something like this:
#define LENGTH 7
in loop():
int j = NUM_LEDS - LENGTH - 1;
for(int i=0;i<NUM_LEDS;i++)
{
leds[j].setRGB(0,0,0);
leds[i].setRGB(255,50,10);
FastLED.show();
j++; if (j >= NUM_LEDS) j = 0;
delay(100);
}
Activity
yesyesuk commentedon Jul 16, 2019
OK, so if noone else comments, I might as well...
leds[i-7].setRGB(0,0,0);This looks just wrong. "i" goes from 0 to NUM_LEDS-1. So you will end up with indexes for leds[] starting with -7. However, an index can't be less than 0. It does not magically wrap around to the end of the array (though, I admit, that would be a handy feature). I'm surprised this runs at all...
One way to solve it is to track the end of the 7 lit LEDs separately. Something like this: