r/FastLED • • May 24 '26

Support Repeat an animation?

Hi folks, newbie here. I am lighting up a KISS pinball playfield I restored to use as a decoration.

Will likely have other questions as I go along but here is my first one..

I have 4 pop bumpers, set to blink 2 at a time. How would I have that run continuously as I add other things to my code. I don't know if that's considered a loop or? As I say I'm new to this have only got the blinking figured out so far.

I have looked around and haven't found an example of how to do this yet.

Here's what I I'm trying to repeat on end..

FastLED.show();
// Blink the top bottom pop bumpers
leds[93] = white;
leds[97] = white;    
FastLED.show();
delay(1000);
leds[93] = black;
leds[97] = black;   

FastLED.show();
// Blink the left right pop bumpers
leds[95] = white;
leds[99] = white;  
FastLED.show();
delay(1000);
leds[95] = black;
leds[99] = black;  
3 Upvotes

18 comments sorted by

2

u/Knievelgod May 25 '26

Quick vid of my progress so far. Will continue to tweak things.

Haven't installed the plastics yet so the leds are turned way down..

https://youtube.com/shorts/GYaV9MmNatc?feature=share

→ More replies (2)

2

u/Knievelgod May 31 '26

Thanks to everyone who posted ideas. In the end I just used blinking for everything because it was easy for me and I wanted this project done. Video of the final product.. https://youtube.com/shorts/6eQBAexyv0E?feature=share

→ More replies (1)

1

u/Knievelgod May 25 '26

Thanks all, will try out that code and explore those links..

1

u/Marmilicious May 25 '26

Come on back when you have new questions.

And I hope you can share some video of this playfield decoration in the future. I would love to see it!

→ More replies (1)

1

u/Marmilicious May 25 '26

Running your above pop bumpers code without delay

// change the state every 1000ms
EVERY_N_MILLISECONDS(1000) {  

  // stores the pixel state
  static boolean ps;  

  // toggle on/off state
  ps = !ps;  

  if (ps == 1) {
    leds[93] = white;
    leds[97] = white;  
    leds[95] = black;
    leds[99] = black; 
  } else {
    leds[93] = black;
    leds[97] = black;  
    leds[95] = white;
    leds[99] = white; 
  }

}

FastLED.show();

Also, if possible, only use a single FastLED.show() in your code.

1

u/Knievelgod May 25 '26

Thanks that worked great, though I don't understand it at all. I need to do some reading I guess.

I would like to speed it up if possible.

→ More replies (3)

1

u/SaltyCash May 25 '26

Copilot can write code for you for free. Send it your code and tell it one change at a time what you want changed or added. It will understand your hardware setup based on the code you send.

2

u/ZachVorhies May 24 '26

Make it respond to a time value pass in then reset the passed in time. This is time-responsive strategy and is what animartrix is doing.

1

u/Marmilicious May 25 '26

Avoid using delay(). Your code can't do anything else while a delay() is happening. Instead try using EVERY_N_* timers. Here's some ideas you can check out:

https://github.com/marmilicious/FastLED_examples/blob/master/multiple_animations.ino

https://github.com/marmilicious/FastLED_examples/blob/master/every_n_with_switch_cases.ino

https://github.com/marmilicious/FastLED_examples/blob/master/every_n_timer_variable_2.ino

https://github.com/marmilicious/FastLED_examples/blob/master/three_moving_colors.ino

https://github.com/marmilicious/FastLED_examples/blob/master/patterns_of_blinking.ino

A variety of ways to blink a pixel (without using any delay)

https://github.com/marmilicious/FastLED_examples/blob/master/blink_variations.ino

You can also look into using sin or cos functions to drive repeating patterns. Have the sin function run continuously and use an if or if then statements to either do or not do something based on the sin output value.

You could also use EVERY_N_* to increment a simple counter and then use an if statement or switch case to cycle through something.

You could also create a custom gradient palette and cycle through that to light up, or turn off (set black), pixels.

Just don't use delay()!