diff options
author | jakob.stendahl <jakob.stendahl@infomedia.dk> | 2022-12-06 11:37:46 +0100 |
---|---|---|
committer | Jakob Stendahl <jakob.stendahl@outlook.com> | 2022-12-06 11:37:46 +0100 |
commit | 98bb009777de51ef8900155cda05c92cc1cb3ab1 (patch) | |
tree | 1b866d1ac3bcba187a397f99b396162f337a6d23 /NeoRuntime/builtin/strobe | |
parent | 629503252de51f3a95ae3dd19ef837012eea9fc2 (diff) | |
download | Luxcena-Neo-98bb009777de51ef8900155cda05c92cc1cb3ab1.tar.gz Luxcena-Neo-98bb009777de51ef8900155cda05c92cc1cb3ab1.zip |
Add some modes
Diffstat (limited to 'NeoRuntime/builtin/strobe')
-rw-r--r-- | NeoRuntime/builtin/strobe/script.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/NeoRuntime/builtin/strobe/script.py b/NeoRuntime/builtin/strobe/script.py new file mode 100644 index 0000000..cd5bffd --- /dev/null +++ b/NeoRuntime/builtin/strobe/script.py @@ -0,0 +1,34 @@ +from luxcena_neo import NeoBehaviour, FloatVariable, IntegerVariable, ColorVariable, BooleanVariable +from time import perf_counter + +class Main(NeoBehaviour): + + def declare_variables(self): + self.declare(FloatVariable("delay", 0.07, min_val=0.01, max_val=0.5, step=0.01)) + self.declare(IntegerVariable("pause", 20, min_val=1, max_val=60)) + self.declare(IntegerVariable("strobe count", 10, min_val=1, max_val=100)) + self.declare(ColorVariable("color", "#fafafa")) + + def on_start(self): + self.strobe_enabled = False + self.strobe_on = False + self.strobe_c = 0 + self.last_inst = perf_counter() + + def each_tick(self): + if (perf_counter() - self.last_inst) > (self.var["delay"].value if self.strobe_enabled else self.var["pause"].value): + if not self.strobe_enabled: self.strobe_enabled = True + self.strobe_c += 1 + set_all(self.var["color"].value if self.strobe_on else 0) + self.strobe_on = not self.strobe_on + if self.strobe_c >= (self.var["strobe count"].value * 2): + self.strobe_c = 0 + self.strobe_enabled = False + self.strobe_on = False + set_all(0) + self.last_inst = perf_counter() + +def set_all(*color): + for i in range(strip.num_pixels()): + strip.set_pixel_color(i, *color) + strip.show()
\ No newline at end of file |