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
3
u/sutaburosu [stavros] Aug 20 '24
This line moves the pulses up one pixel each frame. To move them down a pixel, you'd need to use
leds[i - 1] = pulseColor;, rearrange the for loop to run the other way and change the special handling for the last pixel fromNUM_LEDS - 1to0. Something like this maybe?1
u/Terrible_Medium1649 Aug 26 '24
So I am going to ramp up as I go, but I got the ESP up and going but for whatever reason the sketch that worked on my UNO R3 , does not function the same on the ESP32.
It will do one pulse and then pause for quite awhile before letting out another pulse. Can anyone take a look?
https://pastebin.com/QdNbWFrf
I have tried multiple codes and it works great, besides this one.
1
u/Marmilicious [Marc Miller] Aug 20 '24
You seem to have completely removed the variable part of this by changing the beatsin8 and map lines. I'm guessing that's only for debugging your question? (Otherwise whatever range comes from beatsin8 should be the first part of the map function.)
I also just realized I probably should have named the original example variable_**frequency_**pulses since the speed of the pulses don't change, only the frequency at which they occur. :P