Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FastLED/FastLED.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Kriegsman <kriegsman@tr.org>2015-03-05 05:40:51 +0300
committerMark Kriegsman <kriegsman@tr.org>2015-03-05 05:40:51 +0300
commitc0c8f765f1b01655116cc0c95979203ba05c80ef (patch)
treec840268cbeccf9dc09584af63475a4ab95568de3 /lib8tion.h
parent8dc58ac967f4f32b785b6ba1ba6ec16bc3e57957 (diff)
Added squarewave8.
Diffstat (limited to 'lib8tion.h')
-rw-r--r--lib8tion.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib8tion.h b/lib8tion.h
index 5b98a473..2688d9d6 100644
--- a/lib8tion.h
+++ b/lib8tion.h
@@ -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