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

◆ squarewave8()

LIB8STATIC uint8_t squarewave8 ( uint8_t in,
uint8_t pulsewidth = 128 )

Square wave generator.

Useful for turning a one-byte ever-increasing value into a one-byte value that is either 0 or 255. The width of the output "pulse" is determined by the pulsewidth argument:

if pulsewidth is 255, output is always 255.
if pulsewidth < 255, then
if input < pulsewidth then output is 255
if input >= pulsewidth then output is 0

The output looking like:

255 +--pulsewidth--+
. | |
0 0 +--------(256-pulsewidth)--------
Parameters
ininput value
pulsewidthwidth of the output pulse
Returns
square wave output

Definition at line 802 of file lib8tion.h.

803{
804 if( in < pulsewidth || (pulsewidth == 255)) {
805 return 255;
806 } else {
807 return 0;
808 }
809}

References LIB8STATIC.