I’m trying to only show the fade-down part of the function in an easy way, however I’m not quite right on anything. Any suggestions? I would like to use the BPM only to trigger the fade-out, and not show any fade-up…
@Mark_Kriegsman It’s amazing what some sleep will do. I tried your code structure, but it didn’t quite work out of the box. So, here is what I just came up with:
void loop() {
// set the brightness to a sine wave that moves with a beat
uint8_t bright = beatsin8( BPM, DIMMEST, BRIGHTEST);
//if we are at the bottom
if(bright == DIMMEST+1){ trigger = false; }
//if we are at the top
if(bright == BRIGHTEST-1){ trigger = true; }
//only show the fade out
if(trigger == true){
LEDS.setBrightness( bright ); }
else{
LEDS.setBrightness( 0 ); }
Well, imagine the worst case: you only call beatsin8 once per second, and it HAPPENS to be just when the return value is 128. Every time. The real world isn’t so extreme but the same idea applies.
In other words, because the value is always changing whether you sample it or not, you might accidentally miss certain values. Solutions are: sample often enough that you are sure it never happens, or code the way I did, which is to look for the inflections. Either way works just as well!
Hi Mark, this is potentially a very powerful feature. It is cool to specifiy upper and lower limits, this is exaclty what I did for many animations. Can I “stack” several beatsin8s for more complex waveforms?
I am assuming your function is also meant to sync leds effects to music by hand (?). If so, some remarks from a guy who synced light effects to beats long before he touched the first microcontroller: a “start from zero button” is very helpful to move the starting point ofthe animation within the beat sequence itself. A more fine adjustment of the bpm helps to have the leds running syncron (enough) longer without triggering “start from zero” again. Is there an easy way to do that with your functions?
Thanks and greetings, Stefan
Yeah- I know what you mean and there is an annoying way to do it already, but there really should be an easier way. I sense v3.0.1 coming.
But: read lib8tion.h near the beat functions and there is a little note there about defining your own time base – which means you could reset it at any time.
BEFORE you #include FastLED, do this: #define USE_GET_MILLISECOND_TIMER 1
Then you can (have to!) supply a function like this
uint32_t get_millisecond_timer()
{
return millis();
}
Initially, just define that to return millis() as shown. But then you can change it to return “millis() - resetTime” with resetTime being a global uint32_t, and there you go. Just set resetTime = millis() any time you want to reset the beats to zero.
But really, the beat functions should allow separate time bases and phase offsets to be passed in, for this and other reasons. I’ll put that on the “to do” list.
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:
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() ;
}
////
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.
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: http://pastie.org/10362159