Beats BPM Fastled

FastLED v3.0: One more thing…

Beat generators that generate sine waves (and sawtooth waves) at a BPM you specify. Try this:

#define BPM       60
#define DIMMEST   128
#define BRIGHTEST 255

void loop()
// Put something visible on the LEDs
static uint16_t hue16 = 0;
hue16 += 9;
fill_rainbow( leds, NUM_LEDS, hue16 / 256, 3);

// set the brightness to a sine wave that moves with a beat
uint8_t bright = beatsin8( BPM, DIMMEST, BRIGHTEST);
FastLED.setBrightness( bright );;

Docs are coming, but check lib8tion.h for beat8, beat16, beatsin8, and beatsin16.   Enjoy!

17 plus ones




one share

Shared publiclyView activity
View 13 previous comments
  • Jon Burroughs's profile photo
    Ooooo, this is so much fun, I get such a greater range of randomized hue’s this way:
    byte BEAT_3 = beatsin8( 6, 0, 255);
    byte BEAT_4 = beatsin8( 2, 0, 255);
    average = (BEAT_3 + BEAT_4) / 2;And do start getting more of the possible range of colors, I vary the saturation and brightness of the CHSV assignment:

    brightness= beatsin8( 3, 185, 255);
    saturation= beatsin8( 6, 200, 255);

    leds[i] = CHSV(average , saturation, brightness);

    Oct 30, 2014
  • turgan s's profile photo

    I’m sort of a beginner trying to use Fastled 3.1

    1) I connected a pot to vary the bpm of a fade in / out effect. The pot helps me beat-match to any music manually. However as with standard dj’ing cases I also need a button to reset the timer. Think of it as the play button of cd-dj’s. It will re-start my sine beat at the exact top. The bpm wont change though.

    I read your #define USE_GET_MILLISECOND_TIMER 1 however still not clear. Cannot get my head to wrap around the details and uses of the timing. Do you have any sources I can read on this? or do you have a code example?

    So far I have:
    uint32_t resetTime;
    const int buttonPin = 7;
    void setup() {
    pinMode(buttonPin, INPUT);
    uint32_t get_millisecond_timer()
    return millis();
    void loop(){
    buttonState = digitalRead(buttonPin);
    if (buttonState == HIGH) {
    resetTime = millis() ;

    2) I’m still researching this one but the leds flicker as I change the pot. Is there a way to prevent this flickering, I tried using a capacitor but didnt  seem to help.

    Aug 10, 2015
  • Mark Kriegsman's profile photo
    Change your
    get_millisecond_timer to return millis() – resetTime and try that!
    Aug 10, 2015
  • turgan s's profile photo
    that halted the entire strip at max brightness interestingly. Here is my entire code:
    Aug 10, 2015
  • Mark Kriegsman's profile photo
    You sure that HIGH means Pressed, the way you have it wired? Does the strip run if you hold the button?
    Aug 10, 2015
  • turgan s's profile photo
    Ok now it worked!  With a linear pot and a (play)  button its basically a dj / vj controller now. Thanks!  My final code is here:


Leave a Reply

Your email address will not be published.