Beats BPM Fastled

https://plus.google.com/112916219338292742137/posts/boFjiQNiMAz

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 );

FastLED.show();
}

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

17 plus ones

17

19 comments

19

one share

1
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:
    ////
    #define USE_GET_MILLISECOND_TIMER 1
    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: http://pastie.org/10342234
    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:
    //TGAN SIFIRLAMA DUGMESI
    #define USE_GET_MILLISECOND_TIMER 1
    //TGAN SIFIRLAMA DUGMESI
    
    
    #include "FastLED.h"                                          // FastLED library. Please use the latest development version.
    
    #if FASTLED_VERSION < 3001000
    #error "Requires FastLED 3.1 or later; check github for latest code."
    #endif
    
     
    // Fixed definitions cannot change on the fly.
    #define LED_DT 2                                             // Data pin to connect to the strip.
    //#define LED_CK 11                                             // Clock pin for WS2801 or APA102.
    #define COLOR_ORDER GRB                                       // It's GRB for WS2812 and GBR for APA102.
    #define LED_TYPE WS2812B                                       // Using APA102, WS2812, WS2801. Don't forget to change LEDS.addLeds.
    #define NUM_LEDS 300                                           // Number of LED's.
    
    // Global variables can be changed on the fly.
    uint8_t max_bright = 128;                                      // Overall brightness definition. It can be changed on the fly.
    
    // TGAN Potentiometer VALUE
    int potPin = A0;
    int potValue = 0; 
    int PotMappedOutputValue = 30;
    // TGAN Potentiometer 
    
    //TGAN SIFIRLAMA DUGMESI
    const int buttonPin = 50;
    int buttonState = 0; 
    //TGAN SIFIRLAMA DUGMESI
    
    
    struct CRGB leds[NUM_LEDS];                                   // Initialize our LED array.
    
    // Colours defined for below
    long firstval = 0xff00ff;
    CRGB rgbval(50,0,500);
    CHSV hsvval(150,255,200);
    uint8_t startpos = 0;
    
    //TGAN SIFIRLAMA DUGMESI
    uint32_t resetTime;
    //TGAN SIFIRLAMA DUGMESI
    
    int endpos = NUM_LEDS-1;
    
    uint8_t thishue = 0;
    uint8_t deltahue = 15;
    
    void setup() {
    //TGAN SIFIRLAMA DUGMESI
    pinMode(buttonPin, INPUT); 
    //TGAN SIFIRLAMA DUGMESI
    
    
      delay(1000);                                                // Power-up safety delay.
      Serial.begin(57600);                                        // Initialize serial port for debugging.
    
      LEDS.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS);  // Use this for WS2812
      
      FastLED.setBrightness(max_bright);
      set_max_power_in_volts_and_milliamps(5, 500);               // FastLED Power management set at 5V, 500mA.
    } // setup()
    
    
    ////BPM CODE ////
    //#define BPM       125
    // TGAN Potentiometer 
    //#define BPM       outputValue
    // TGAN Potentiometer 
    
    #define DIMMEST   2
    #define BRIGHTEST 255
    ///// BPM CODE END ////
    
    uint32_t get_millisecond_timer()
    {
    return millis()-resetTime  ;
    }
    //TGAN SIFIRLAMA DUGMESI
    
    void loop () {        // Several different ways to fill the strand with a solid colour.
    buttonState = digitalRead(buttonPin);
    if (buttonState == HIGH) { 
    resetTime = millis() ;
    } ;
    
    potValue = analogRead(potPin); 
    PotMappedOutputValue = map(potValue, 0, 1023, 40, 145);
    
    Serial.println(potValue);
    
    ////BPM CODE ////
    // 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(PotMappedOutputValue, DIMMEST, BRIGHTEST);
      FastLED.setBrightness( bright );
      FastLED.show();
    ///// BPM CODE END ////
    
      show_at_max_brightness_for_power();                         // Power managed display
    
    } // loop()

     

Leave a Reply