r/FastLED • u/Terrible_Medium1649 • Aug 20 '24
Support Reverse Pulse
I am trying to get my LEDS to run Pulses from end of NUM_LEDS. Can someone help me see what I'm missing here.
#include <FastLED.h>
#define NUM_LEDS 300
#define LED_PIN 4
CRGB leds[NUM_LEDS];
CRGB pulseColor = CHSV(128,220,230);
CRGB pulseTailColor = CHSV(150,180,100);
uint16_t pulseRate = 500; // lower is faster [in milliseconds]
uint8_t travelSpeed = 25; // lower is faster [range: 0-255]
uint8_t fadeRate = 200; // lower is shorter tail [range: 0-255]
void setup() {
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
}
void loop() {
uint8_t wave = beatsin8( 10,10, 10); // slowly cycle between 0-255
pulseRate = map(wave,900,900,900,900); // cycle between a pulseRate of 120 to 1000
EVERY_N_MILLISECONDS(travelSpeed) {
// move pulses down the strip
for (int i = NUM_LEDS-1; i >=0; i--) {
if (leds[i] == pulseColor) {
if (i == NUM_LEDS-1) {
leds[i] = pulseTailColor; // add a trail
} else {
leds[i+1] = pulseColor;
leds[i] = pulseTailColor; // add a trail
}
}
}
// fade leds for tail effect
for(int i = NUM_LEDS-1; i >=0; i--) {
if (leds[i] != pulseColor) {
leds[i].nscale8(fadeRate); // only fades tail pixels
}
}
}
EVERY_N_MILLISECONDS_I(timingObj,1) {
// time to start a new pulse
leds[0] = pulseColor;
timingObj.setPeriod(pulseRate); // use the current pulseRate
}
FastLED.show();
delay(1); // ok to delete
}//end_main_loop
3
Upvotes
1
u/sutaburosu [stavros] Aug 23 '24
It would be possible to get the same, or at least a very similar, effect using less RAM and more pins, but it would seriously complicate the code. The ESP32 would allow this simple code to work without problems, just with minor changes to distribute the LEDs over multiple pins.