From 98bb009777de51ef8900155cda05c92cc1cb3ab1 Mon Sep 17 00:00:00 2001 From: "jakob.stendahl" Date: Tue, 6 Dec 2022 11:37:46 +0100 Subject: Add some modes --- NeoRuntime/builtin/strobe/script.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 NeoRuntime/builtin/strobe/script.py (limited to 'NeoRuntime/builtin/strobe/script.py') 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 -- cgit v1.2.3