FastLED Wave Experiments: void dot(){   static byte middle =0;

FastLED Wave Experiments:

void dot(){
static byte middle =0;
static byte side =0;
static byte other =0;

currentMillis = millis();
if(currentMillis - previousMillis > 12) {
count++;
if (count == 255) {
count = 0; }
byte x = quadwave8(count);
other = map(x, 0, 255, 24, (NUM_LEDS-12));
side = map(x, 0, 255, 1, NUM_LEDS);
middle =map(x, 0, 255, 48, NUM_LEDS-24);
leds[middle] = CRGB::Purple;
leds[side] = CRGB::Blue;
leds[other] = CRGB::Aqua;

LEDS.show();
for(byte i = 0; i < NUM_LEDS; i++){
 leds[i].nscale8(180); 
}
previousMillis = currentMillis;
LEDS.show();

}
}

f4941f43e851fa053b6dc5ebffe74a2c.gif

There’s some hard coded values in there, ie. NUM_LEDS-24. In my case, NUM_LEDS = 24, so I’ll need to ‘un-hardcode’ those map statements (I think there’s 96 LED’s in John’s array). Also, I believe it should be:

side = map(x, 0, 255, 0, NUM_LEDS-1);

Otherwise, at some point, you’ll be referring to leds[NUM_LEDS], which is 1 too many.

If he used all the sections, there ought to be 144 pixels there. The mapping is just so all three dots don’t end up moving the same distance. So you can either hardcode the values, or you can mathematically figure out how far you want each one to travel.

I ended up with: http://pastebin.com/XZasRPTa

Sorry, but I took out the non-blocking delay, as I’ve had some issues with it when using FastLED recently.

You took out the non-blocking and introduced a blocking delay? That’s going backwards. You should not be using a blocking delay. You can do a lot of other things in that 4ms that you’re blocking.

You’re absolutely right. The reason I did so, is because I had a problem with the non-blocking delay. As an example, see (on my Arduino UNO):

http://pastebin.com/wxgaNee1

In this example, twinkle() with the standard delay works as expected, while twinkle2() with the non-blocking delay does not. Meanwhile, twinkle3() with some Serial.print statements and a non-blocking delay DOES work.

Update: Sorted it out. previousMillis assignment should’ve been up a couple of lines.

I was able to fix your problem with the twinkles. LOL

void twinkle2() {
currentMillis = millis();
if(currentMillis - previousMillis >= 20) {
int i = random8(NUM_LEDS);
if (i < NUM_LEDS) {
leds[i] = CHSV(50, 100, 255);
}
for (int j = 0; j < NUM_LEDS; j++) {
leds[j].fadeToBlackBy(8);
}
LEDS.show();
previousMillis = currentMillis;
}
}

Yeah. Just figured that out. . . :smiley:

I’ve updated my original pastebin with working non-blocking delays.

No need to store currentMillis at all. Save yourself a few bytes. If you do this a lot, save yourself a lot of bytes.

volatile long prevMillis = 0;
const uint8_t pause = 25; // why chase code at some later time if you want to change this.

void someFunction() {
if (millis() - prevMillis >= pause) {
// makeCoffee();
prevMillis = millis();
}
}

I generally set my global pause to 1000. Then, each respective function gets some fraction of that, pause/100, pause/200, etc.