I come here with what most probably is a very basic usage question.

I come here with what most probably is a very basic usage question. I am still dealing with the basics…

How do I handle the following code in order to have each of the 5 pixels cycling at a different speed?

#include “FastLED.h”
#define NUM_LEDS 5
CRGB leds[NUM_LEDS];

void setup() {
FastLED.addLeds<UCS2903, 49>(leds, NUM_LEDS);
}

void loop() {
static uint8_t hue = 0;
FastLED.showColor(CHSV(hue++, 255, 255));
delay(100);
}

Define an array with the determined speeds you’d like the LEDs to change to and an array to hold what they’re currently at.

Then make a loop that increments the current leds color and then sets that color using something like leds[i]=CHSV(currentcolor[i],255,255);

Leo, if it’s just 5 pixels (and if I understand what you’re wanting to do) I might try out using five hue variables (hue1, hue2, etc) and also five EVERY_N_MILLISECONDS setups, one for each pixel.
I’m curious what you come up with.

so far I have this

#include “FastLED.h”
#define NUM_LEDS 5
CRGB leds[NUM_LEDS];

static uint8_t hue1 = 0;
static uint8_t hue2 = 72;
static uint8_t hue3 = 144;
static uint8_t hue4 = 216;
static uint8_t hue5 = 288;

void setup() {
FastLED.addLeds<UCS2903, 49>(leds, NUM_LEDS);
}

void loop() {
leds[0] = (CHSV(hue1++, 255, 255));
leds[1] = (CHSV(hue2++, 255, 255));
leds[2] = (CHSV(hue3++, 255, 255));
leds[3] = (CHSV(hue4++, 255, 255));
leds[4] = (CHSV(hue5++, 255, 255));
FastLED.show();
delay(100);
}

I am using “static uint8_t” because I saw it in use, not because I understand what it does

would you be so kind to guide me with “EVERY_N_MILLISECONDS”?

danke!

I don’t think you need to use static uint8_t, just unit8_t.
Here’s an example of using EVERY_N_MILLISECONDS:

Here’s another that uses EVERY_N_SECONDS, which works the same except you give it a number of seconds instead of milliseconds:

what do you think? I have it running like this:

#include “FastLED.h”
#define NUM_LEDS 5
CRGB leds[NUM_LEDS];

uint8_t hue0 = 0;
uint8_t hue1 = 72;
uint8_t hue2 = 144;
uint8_t hue3 = 216;
uint8_t hue4 = 288;

void setup() {
delay(3000);
FastLED.addLeds<UCS2903, 49>(leds, NUM_LEDS);
}

void loop() {
led0();
led1();
led2();
led3();
led4();
FastLED.show();
}

void led0() {
EVERY_N_MILLISECONDS(10)
leds[0] = (CHSV(hue0++, 255, 255));
}

void led1() {
EVERY_N_MILLISECONDS(100)
leds[1] = (CHSV(hue1++, 255, 255));
}

void led2() {
EVERY_N_MILLISECONDS(200)
leds[2] = (CHSV(hue2++, 255, 255));
}

void led3() {
EVERY_N_MILLISECONDS(500)
leds[3] = (CHSV(hue3++, 255, 255));
}

void led4() {
EVERY_N_MILLISECONDS(1000)
leds[4] = (CHSV(hue4++, 255, 255));
}

I think the EVERY_N_MILLISECONDS lines need to be inside the main loop. (I think @Mark_Kriegsman ​ said that.) Also note the use of braces { } around the code that will run every N milliseconds. But otherwise, yes, I think you got it. :slight_smile:

ack… EVERY_N_MILLISECONDS is built into fastled to replace (help) with the currentmillis()-previousmillis()?

dammit… ive been wasting a lot of time getting my projects to run if i can just use this!

Ack, my brain must have slipped the other day. Obviously using EVERY_N* works fine outside of the main loop and in a subroutine, as I did that in my first example provided above. (It must have been something else I remember Mark saying needed to be inside the main loop.) Did you get it all working @Leo_Bettinelli ? I would still suggest the use of the braces though, so for your example:
void led0() {
EVERY_N_MILLISECONDS(10) { // <–don’t forget these braces
leds[0] = (CHSV(hue0++, 255, 255));
} // <–every_n closing brace
}

@Kelvin_Mead , yes the addition of EVERY_N* to FastLED is wonderful. It definitely simplifies the code, and also makes it much more readable.

ey marc!

it obviously work outside of the main loop because it was already working for me when you mentioned that it needs to be inside of the loop. :slight_smile:

I take your advice on braces!

super thank you!