FastLED 3.9.3
Loading...
Searching...
No Matches
Waveform Beat Generators

Detailed Description

Waveform generators that reset at a given number of "beats per minute" (BPM).

The standard "beat" functions generate "sawtooth" waves which rise from 0 up to a max value and then reset, continuously repeating that cycle at the specified frequency (BPM).

The "sin" versions function similarly, but create an oscillating sine wave at the specified frequency.

BPM can be supplied two ways. The simpler way of specifying BPM is as a simple 8-bit integer from 1-255, (e.g., "120"). The more sophisticated way of specifying BPM allows for fractional "Q8.8" fixed point number (an accum88) with an 8-bit integer part and an 8-bit fractional part. The easiest way to construct this is to multiply a floating point BPM value (e.g. 120.3) by 256, (e.g. resulting in 30796 in this case), and pass that as the 16-bit BPM argument.

Originally these functions were designed to make an entire animation project pulse. with brightness. For that effect, add this line just above your existing call to "FastLED.show()":

uint8_t bright = beatsin8( 60 /*BPM*/, 192 /*dimmest*/, 255 /*brightest*/ ));
CFastLED FastLED
Global LED strip management instance.
Definition FastLED.cpp:33
void setBrightness(uint8_t scale)
Set the global brightness scaling.
Definition FastLED.h:722
void show(uint8_t scale)
Update all our controllers with the current led colors, using the passed in brightness.
Definition FastLED.cpp:82
LIB8STATIC uint8_t beatsin8(accum88 beats_per_minute, uint8_t lowest=0, uint8_t highest=255, uint32_t timebase=0, uint8_t phase_offset=0)
Generates an 8-bit sine wave at a given BPM that oscillates within a given range.
Definition lib8tion.h:980

The entire animation will now pulse between brightness 192 and 255 once per second.

Warning
Any "BPM88" parameter MUST always be provided in Q8.8 format!
Note
The beat generators need access to a millisecond counter to track elapsed time. See GET_MILLIS for reference. When using the Arduino millis() function, accuracy is a bit better than one part in a thousand.

Functions

LIB8STATIC uint16_t beat88 (accum88 beats_per_minute_88, uint32_t timebase=0)
 Generates a 16-bit "sawtooth" wave at a given BPM, with BPM specified in Q8.8 fixed-point format.
 
LIB8STATIC uint16_t beat16 (accum88 beats_per_minute, uint32_t timebase=0)
 Generates a 16-bit "sawtooth" wave at a given BPM.
 
LIB8STATIC uint8_t beat8 (accum88 beats_per_minute, uint32_t timebase=0)
 Generates an 8-bit "sawtooth" wave at a given BPM.
 
LIB8STATIC uint16_t beatsin88 (accum88 beats_per_minute_88, uint16_t lowest=0, uint16_t highest=65535, uint32_t timebase=0, uint16_t phase_offset=0)
 Generates a 16-bit sine wave at a given BPM that oscillates within a given range.
 
LIB8STATIC uint16_t beatsin16 (accum88 beats_per_minute, uint16_t lowest=0, uint16_t highest=65535, uint32_t timebase=0, uint16_t phase_offset=0)
 Generates a 16-bit sine wave at a given BPM that oscillates within a given range.
 
LIB8STATIC uint8_t beatsin8 (accum88 beats_per_minute, uint8_t lowest=0, uint8_t highest=255, uint32_t timebase=0, uint8_t phase_offset=0)
 Generates an 8-bit sine wave at a given BPM that oscillates within a given range.
 

Function Documentation

◆ beat16()

LIB8STATIC uint16_t beat16 ( accum88 beats_per_minute,
uint32_t timebase = 0 )

Generates a 16-bit "sawtooth" wave at a given BPM.

Parameters
beats_per_minutethe frequency of the wave, in decimal
timebasethe time offset of the wave from the millis() timer

Definition at line 918 of file lib8tion.h.

◆ beat8()

LIB8STATIC uint8_t beat8 ( accum88 beats_per_minute,
uint32_t timebase = 0 )

Generates an 8-bit "sawtooth" wave at a given BPM.

Parameters
beats_per_minutethe frequency of the wave, in decimal
timebasethe time offset of the wave from the millis() timer

Definition at line 928 of file lib8tion.h.

◆ beat88()

LIB8STATIC uint16_t beat88 ( accum88 beats_per_minute_88,
uint32_t 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 902 of file lib8tion.h.

◆ beatsin16()

LIB8STATIC uint16_t beatsin16 ( accum88 beats_per_minute,
uint16_t lowest = 0,
uint16_t highest = 65535,
uint32_t timebase = 0,
uint16_t phase_offset = 0 )

Generates a 16-bit sine wave at a given BPM that oscillates within a given range.

Parameters
beats_per_minutethe frequency of the wave, in decimal
lowestthe lowest output value of the sine wave
highestthe highest output value of the sine wave
timebasethe time offset of the wave from the millis() timer
phase_offsetphase offset of the wave from the current position

Definition at line 962 of file lib8tion.h.

◆ beatsin8()

LIB8STATIC uint8_t beatsin8 ( accum88 beats_per_minute,
uint8_t lowest = 0,
uint8_t highest = 255,
uint32_t timebase = 0,
uint8_t phase_offset = 0 )

Generates an 8-bit sine wave at a given BPM that oscillates within a given range.

Parameters
beats_per_minutethe frequency of the wave, in decimal
lowestthe lowest output value of the sine wave
highestthe highest output value of the sine wave
timebasethe time offset of the wave from the millis() timer
phase_offsetphase offset of the wave from the current position

Definition at line 980 of file lib8tion.h.

◆ beatsin88()

LIB8STATIC uint16_t beatsin88 ( accum88 beats_per_minute_88,
uint16_t lowest = 0,
uint16_t highest = 65535,
uint32_t timebase = 0,
uint16_t phase_offset = 0 )

Generates a 16-bit sine wave at a given BPM that oscillates within a given range.

Parameters
beats_per_minute_88the frequency of the wave, in Q8.8 format
lowestthe lowest output value of the sine wave
highestthe highest output value of the sine wave
timebasethe time offset of the wave from the millis() timer
phase_offsetphase offset of the wave from the current position
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 beatsin16() or beatsin8().

Definition at line 944 of file lib8tion.h.