DiscoStrobe Flashing rainbow lights that zoom back and forth to a beat.

Flashing rainbow lights that zoom back and forth to a beat.
(Video is best at full screen / full volume.)

Step 1. Turn off the room lights.
Step 2. Crank up house/disco music.
Step 3. Run this animation on hundreds of LEDs.
Step 4. Boogie and/or seizure. (Sorry.)

Heavily commented source code is here:

Code shows one technique for staying sync’d to a specific frame rate (i.e. 100 FPS), and other than that it’s a couple of layers of animation design on top of each other: the lowest level just draws dashes of light on the led strip. The next level up moves those dashes back and forth. The level above that shifts and changes the parameters of the motion over time.

The stroboscopic effect is achieved pretty simply: only every fourth frame is actually lit up on the LEDs. The other 3/4ths of the time, the strip is actually totally black. (If you think about it, regular xenon strobe lights are off most of the time, too.)

Lots of parameters for people to play with, and the code is relatively resilient when poked.


Most excellent!

First of all: Respect!
For me it would be interesting to see the animation following different music styles (guitar, piano, (minimal) techno, full on rave) with the very same parameters. Linking bandlevels to parameters in a complex way is one thing - finding the right thresholds and actions fitting for any audio input is really tricky (but possible). The modular concept with stacked layers is definitely a good approach.
I’m happy that you stepped into that topic! :slight_smile:

Edit: Ah, sorry, I see you work with a fixed bpm number. Reminds me that I wrote a TAP-function (including shift and pause) for manual sync before I found the MSGEQ7.
Anyway, it’s a cool pattern you wrote and very well commented code!

Yep- this is totally standalone (like most strobe lights!), but could easily be hooked to beat detection, either via tapping or audio input.

I think a fun thing would be to receive BPM via Bluetooth, and then that data could come from PC/Mac or smartphone or who knows what.

If you’ve got some good beat detection code, maybe you could share it? I’m still pondering the best way to do that on AVR, with minimal/no hardware, and I have a theory, but it needs time that it doesn’t have right now.

Anyway, if you build on top of this, please share the results! Layer FOUR: audio sync!

I found that an accelerometer can be well abused for a minimal stand alone beat detection.
The beat detection itself is not trivial - except you assume that there is always a beat present and not changing rapidly. Than it needs just some auto gain function - like moving the threshold window up and down until you get a stable signal within a predefined range.
Since the Noise Smearing I coded nothing new led related.
It’s really a pity that a day has only 24 hours and I still need to sleep some of them. Within the last half year I used my rare free time to step deep into photography - and coded while doing so stuff for a hacked Canon firmware and an awesome RAW developing tool… But basically I spend not much time in front of computers anymore except for developing digital negatives… Greetings!

Are you willing to disclosure your idea with “minimal/no hardware”? I’m interested in the hardware part.

Well, if all you care about is beat, you don’t care at about high frequency signals. And that means that maybe you could do a simple RC circuit (low-pass filter -style) between an audio signal and an Arduino ADC. It might take just one resistor and one capacitor… and some math.

The key idea is to totally ignore all high frequency data, and thus sidestep the need for MSGEQ, FFT, etc. Might even work on poor slow AVRs.

And then there’s the idea for having an internal free-running metronome (as the code above does now) that is merely adjusted faster or slower as beats arrive “early” or “late”…

“It might take just one resistor and one capacitor”
I tryed that and ended up with an additional Schmitt-trigger for reliable results. But please report how it works for you in case you test it.
The accelerometer also reacts just on very low frequencies with a stable delay depending on the distance to the speakers.

That is super flashtastic. That’s for sharing more inspiration Mark!

Hi Mark,
Like @Stefan_Petrick I also would be in favour of syncing it to music. If you go with MSGEQ7 there is a BPM snipplet found on

int find_average(int ary[], int siz){
double sum = 0;
for (int i = 0; i < siz; i++){
sum += ary[i];
return sum/siz;

void loop(){
int new_bass = spectrumValue[0] + spectrumValue[1];
int new_snare = spectrumValue[3];
int new_hat = spectrumValue[6] + spectrumValue[5];

if ((new_snare/find_average(snare, frames)) > 1){

if ((new_hay/find_average(hat, frames)) > 1){

if ((new_bass/find_average(bass, frames)) > 1){

hat[frame] = new_hat;
snare[frame] = new_snare;
bass[frame] = new_bass;
if (frame >= frames) frame=0;

Alternatively you can do it with an OP-amp like Jeremy Blum in his great tutorial.

The tutorial also includes very nice effects but I was not able to port his code to FastLED.
Maybe someone can help?

Where do I find fastLed version 3.1? I see only 3.0.3 on github

There’s a branch called FastLED3.1:

As for audio input there are two ways to go: “audio-reactive” (as in the code shown above), where it just looks at the spectrum bins and reacts immediately based on those values, and “beat-sync”. In a beat-sync setup, the code as has in internal metronome that is always ticking at a steady beat, and the audio input is analyzed to see if the internal BPM metronome needs to be adjusted. Audio-reactive code is pretty easy; real beat-sync code is much more interesting – and much less common.

BUT: let’s make it a challenge here! There’s lots of audio-reactive code out there already – who wants to hook it up to this example code and show what they can do?!

It’s also worth noting that if your animation has a ‘beat’ to it that’s even remotely close to the beat of the music you’re hearing, your brain will put the two together and make you feel like they’re [mostly] in sync. I can’t tell you how many times someone has watched a project that I’ve built (that has NO audio input), while music is playing, and they’ve said “Wow! It’s cool how it goes in time to the music!” At this point I’ve learned just to say “Thanks! I’m glad you like the way it looks!” (And then I laugh a little inside, and make a note to tell Dan that IT happened again.)

Do you know of any beat-sync code out there? I’ve got the MAX chip based AGC microphone that Adafruit sells… combining it with real beat-sync would be amazine. I’m especially interested in coding animations for Transitions between beats…

Is there a way to change the colors in this code? I’d like to change the colors to purple and green or orange and green for Halloween.

Oh good question! I’ll see if I can post a palette version…

@jason_brader Check this out: https://gist.github.com/kriegsman/626dca2f9d2189bd82ca

It’s essentially the same code as the original DiscoStrobe code, except that instead of just using the HSV color wheel, it uses a color palette that you can define. I preloaded it with a palette with a purple, green, and orange that look Halloween-y to me, but you can put any colors you want into the color palette, just using hex codes or color names, etc.

Let me know it works for you!

great example. Related to beat syncinc, I am trying to figure out a solution where a software music player or DJ software can broadcast “beat taps” on the network e.g. via UDP packets so that I can receive those with my Yun Shield. I am trying to keep this complcated beat detection out of the Arduino and just send in the beats automatically. While I though this is very trivial, it seems not to exist yet. Anyone heard about anything like that? As an advanced version I would like to extend those packets with more information e.g. a selection of LED effect to show in the first place and maybe some other adjustable parameters for those effects. I could then code this effect selection into the MP3 tags.