FastLED 3.9.15
Loading...
Searching...
No Matches

◆ beat88()

LIB8STATIC u16 fl::beat88 ( accum88 beats_per_minute_88,
u32 timebase = 0 )

Generates a 16-bit "sawtooth" wave at a given BPM, with BPM specified in Q8.8 fixed-point format.

Parameters
beats_per_minute_88the frequency of the wave, in Q8.8 format
timebasethe time offset of the wave from the millis() timer
Warning
The BPM parameter MUST be provided in Q8.8 format! E.g. for 120 BPM it would be 120*256 = 30720. If you just want to specify "120", use beat16() or beat8().

Definition at line 26 of file beat.h.

26 {
27 // BPM is 'beats per minute', or 'beats per 60000ms'.
28 // To avoid using the (slower) division operator, we
29 // want to convert 'beats per 60000ms' to 'beats per 65536ms',
30 // and then use a simple, fast bit-shift to divide by 65536.
31 //
32 // The ratio 65536:60000 is 279.620266667:256; we'll call it 280:256.
33 // The conversion is accurate to about 0.05%, more or less,
34 // e.g. if you ask for "120 BPM", you'll get about "119.93".
35 return (((fl::millis()) - timebase) * beats_per_minute_88 * 280) >> 16;
36}
fl::u32 millis()
Universal millisecond timer - returns milliseconds since system startup.