Is it possible to initialize the beatsin8() function to a fixed starting point? Right now, when I call the function, it returns wherever it’s currently at in the wave form. I would like it to always start from 0 whenever I call it.
Yes. On the 3.1 branch, you can specify a base timestamp.
uint8_t beatsin8(
accum88 beats_per_minute,
uint8_t lowest=0,
uint8_t highest=255,
uint32_t timebase=0,
uint8_t phase_offset=0)
So when you want to ‘zero’ out the beat, do this:
uint32_t zerotime = millis();
And then when you call beatsin8, pass in ‘zerotime’ as the fourth argument:
uint8_t wave = beatsin8( 120, 0, 255, zerotime);
That should do it. Let me know if it doesn’t work! (Or if it does, too!)
Oooh nice, that’s great to know.
That makes this function much more awesome.
Worked like a charm! Here is the code I used to reset the BPM generator upon receiving a new tempo command :
if (new_BPM)
{
zerotime = millis();
tempo = beatsin8( data2, 0, NUM_ROWS, zerotime );
new_BPM = false;
}
else
{
tempo = beatsin8( data2, 0, NUM_ROWS );
}
I think you might mean this:
if (new_BPM) {
zerotime = millis();
new_BPM = false;
}
tempo = beatsin8( data2, 0, NUM_ROWS, zerotime );
Basically, you have to always tell beatsin8 what you want the base time to be; it doesn’t have any internal state.
@Mark_Kriegsman OK, that makes sense and operates as expected, thank you.