diff options
author | Mark Kriegsman <kriegsman@tr.org> | 2015-03-05 05:40:51 +0300 |
---|---|---|
committer | Mark Kriegsman <kriegsman@tr.org> | 2015-03-05 05:40:51 +0300 |
commit | c0c8f765f1b01655116cc0c95979203ba05c80ef (patch) | |
tree | c840268cbeccf9dc09584af63475a4ab95568de3 /lib8tion.h | |
parent | 8dc58ac967f4f32b785b6ba1ba6ec16bc3e57957 (diff) |
Added squarewave8.
Diffstat (limited to 'lib8tion.h')
-rw-r--r-- | lib8tion.h | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -1745,6 +1745,30 @@ LIB8STATIC uint8_t cubicwave8(uint8_t in) return ease8InOutCubic( triwave8( in)); } +// squarewave8: 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 +// +// 255 +--pulsewidth--+ +// . | | +// 0 0 +--------(256-pulsewidth)-------- +// +LIB8STATIC uint8_t squarewave8( uint8_t in, uint8_t pulsewidth=128) +{ + if( in < pulsewidth || (pulsewidth == 255)) { + return 255; + } else { + return 0; + } +} + + // sqrt16: square root for 16-bit integers |