aboutsummaryrefslogtreecommitdiff
path: root/main/pattern
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2025-12-07 16:02:20 -0700
committerJosh Rahm <joshuarahm@gmail.com>2025-12-07 16:02:20 -0700
commit44c7f7a675d2cdb0281322f38be3227ef4fb1df2 (patch)
tree4da919b59129c1447fa9aec45e6cd51bf70dc071 /main/pattern
parentc9efee6f3ffcf19e139d72d946aa4d837bbcbb9e (diff)
downloadesp32-ws2812b-44c7f7a675d2cdb0281322f38be3227ef4fb1df2.tar.gz
esp32-ws2812b-44c7f7a675d2cdb0281322f38be3227ef4fb1df2.tar.bz2
esp32-ws2812b-44c7f7a675d2cdb0281322f38be3227ef4fb1df2.zip
Add a "reset defaults" button and handler.
Diffstat (limited to 'main/pattern')
-rw-r--r--main/pattern/twinkle.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/main/pattern/twinkle.c b/main/pattern/twinkle.c
index d23b111..450cda6 100644
--- a/main/pattern/twinkle.c
+++ b/main/pattern/twinkle.c
@@ -1,8 +1,8 @@
+#include "pattern/twinkle.h"
+
#include <stdint.h>
#include <stdlib.h>
-#include "pattern/twinkle.h"
-
// The shape of a "spike"
uint8_t w_arr[91] = {1, 2, 4, 7, 11, 17, 24, 33, 44, 56, 70, 85,
101, 117, 134, 151, 167, 183, 197, 210, 222, 232, 240, 247,
@@ -36,7 +36,7 @@ static uint8_t pseudo_random(uint8_t x)
}
/* Produces a randomize "twinkle" effect. */
-uint8_t twinkle(uint32_t time, size_t x, uint8_t amt)
+static uint8_t twinkle_raw(uint32_t time, size_t x, uint8_t amt)
{
uint8_t time_offset = pseudo_random(x);
@@ -51,3 +51,13 @@ uint8_t twinkle(uint32_t time, size_t x, uint8_t amt)
return 0;
}
}
+
+uint8_t twinkle(uint32_t time, size_t x, uint8_t amt)
+{
+ if (time % 2 == 0) {
+ return twinkle_raw(time / 2, x, amt);
+ } else {
+ return (twinkle_raw(time / 2, x, amt) + twinkle_raw(time / 2 + 1, x, amt)) /
+ 2;
+ }
+}