Compare commits
2 Commits
patterns
...
f8851d2e7c
| Author | SHA1 | Date | |
|---|---|---|---|
| f8851d2e7c | |||
| 12e242724e |
@@ -3,6 +3,24 @@ from neopixel import NeoPixel
|
|||||||
import utime
|
import utime
|
||||||
import random
|
import random
|
||||||
|
|
||||||
|
# Short-key parameter mapping for convenience setters
|
||||||
|
param_mapping = {
|
||||||
|
"pt": "selected",
|
||||||
|
"pa": "selected",
|
||||||
|
"cl": "colors",
|
||||||
|
"br": "brightness",
|
||||||
|
"dl": "delay",
|
||||||
|
"nl": "num_leds",
|
||||||
|
"co": "color_order",
|
||||||
|
"lp": "led_pin",
|
||||||
|
"n1": "n1",
|
||||||
|
"n2": "n2",
|
||||||
|
"n3": "n3",
|
||||||
|
"n4": "n4",
|
||||||
|
"n5": "n5",
|
||||||
|
"n6": "n6",
|
||||||
|
}
|
||||||
|
|
||||||
class Patterns:
|
class Patterns:
|
||||||
def __init__(self, pin, num_leds, color1=(0,0,0), color2=(0,0,0), brightness=127, selected="rainbow_cycle", delay=100):
|
def __init__(self, pin, num_leds, color1=(0,0,0), color2=(0,0,0), brightness=127, selected="rainbow_cycle", delay=100):
|
||||||
self.n = NeoPixel(Pin(pin, Pin.OUT), num_leds)
|
self.n = NeoPixel(Pin(pin, Pin.OUT), num_leds)
|
||||||
@@ -62,6 +80,13 @@ class Patterns:
|
|||||||
if self.patterns[self.selected]:
|
if self.patterns[self.selected]:
|
||||||
self.patterns[self.selected]()
|
self.patterns[self.selected]()
|
||||||
|
|
||||||
|
def set_param(self, key, value):
|
||||||
|
if key in param_mapping:
|
||||||
|
setattr(self, param_mapping[key], value)
|
||||||
|
return True
|
||||||
|
print(f"Invalid parameter: {key}")
|
||||||
|
return False
|
||||||
|
|
||||||
def update_num_leds(self, pin, num_leds):
|
def update_num_leds(self, pin, num_leds):
|
||||||
self.n = NeoPixel(Pin(pin, Pin.OUT), num_leds)
|
self.n = NeoPixel(Pin(pin, Pin.OUT), num_leds)
|
||||||
self.num_leds = num_leds
|
self.num_leds = num_leds
|
||||||
|
|||||||
45
test/patterns.py
Normal file
45
test/patterns.py
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import utime
|
||||||
|
from machine import WDT
|
||||||
|
from settings import Settings
|
||||||
|
from patterns import Patterns
|
||||||
|
|
||||||
|
|
||||||
|
def run():
|
||||||
|
s = Settings()
|
||||||
|
pin = s.get("led_pin", 10)
|
||||||
|
num = s.get("num_leds", 30)
|
||||||
|
|
||||||
|
p = Patterns(pin=pin, num_leds=num)
|
||||||
|
wdt = WDT(timeout=10000)
|
||||||
|
|
||||||
|
# Baseline params
|
||||||
|
p.set_param("br", 64)
|
||||||
|
p.set_param("dl", 500)
|
||||||
|
p.set_param("cl", [(255, 0, 0), (0, 0, 255)])
|
||||||
|
p.set_param("n1", 200)
|
||||||
|
p.set_param("n2", 200)
|
||||||
|
p.set_param("n3", 1)
|
||||||
|
p.set_param("n4", 1)
|
||||||
|
|
||||||
|
for name, fn in p.patterns.items():
|
||||||
|
if fn is None:
|
||||||
|
continue
|
||||||
|
print(name)
|
||||||
|
p.set_param("pt", name)
|
||||||
|
|
||||||
|
start = utime.ticks_ms()
|
||||||
|
while utime.ticks_diff(utime.ticks_ms(), start) < 2000:
|
||||||
|
p.tick()
|
||||||
|
wdt.feed()
|
||||||
|
utime.sleep_ms(10)
|
||||||
|
|
||||||
|
p.set_param("pt", "off")
|
||||||
|
p.tick()
|
||||||
|
utime.sleep_ms(200)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
run()
|
||||||
|
|
||||||
|
|
||||||
34
test/patterns/bidirectional_scanner.py
Normal file
34
test/patterns/bidirectional_scanner.py
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import utime
|
||||||
|
from machine import WDT
|
||||||
|
from settings import Settings
|
||||||
|
from patterns import Patterns
|
||||||
|
|
||||||
|
|
||||||
|
def run():
|
||||||
|
s = Settings()
|
||||||
|
pin = s.get("led_pin", 10)
|
||||||
|
num = s.get("num_leds", 30)
|
||||||
|
|
||||||
|
p = Patterns(pin=pin, num_leds=num)
|
||||||
|
wdt = WDT(timeout=10000)
|
||||||
|
p.set_param("br", 127)
|
||||||
|
p.set_param("dl", 50)
|
||||||
|
p.set_param("cl", [(0, 255, 0), (0, 255, 0)])
|
||||||
|
p.set_param("pt", "bidirectional_scanner")
|
||||||
|
|
||||||
|
start = utime.ticks_ms()
|
||||||
|
while utime.ticks_diff(utime.ticks_ms(), start) < 1500:
|
||||||
|
p.tick()
|
||||||
|
wdt.feed()
|
||||||
|
utime.sleep_ms(10)
|
||||||
|
|
||||||
|
p.set_param("pt", "off")
|
||||||
|
p.tick()
|
||||||
|
utime.sleep_ms(100)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
run()
|
||||||
|
|
||||||
|
|
||||||
34
test/patterns/blink.py
Normal file
34
test/patterns/blink.py
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import utime
|
||||||
|
from machine import WDT
|
||||||
|
from settings import Settings
|
||||||
|
from patterns import Patterns
|
||||||
|
|
||||||
|
|
||||||
|
def run():
|
||||||
|
s = Settings()
|
||||||
|
pin = s.get("led_pin", 10)
|
||||||
|
num = s.get("num_leds", 30)
|
||||||
|
|
||||||
|
p = Patterns(pin=pin, num_leds=num)
|
||||||
|
wdt = WDT(timeout=10000)
|
||||||
|
p.set_param("br", 64)
|
||||||
|
p.set_param("dl", 200)
|
||||||
|
p.set_param("cl", [(255, 0, 0), (0, 0, 255)])
|
||||||
|
p.set_param("pt", "blink")
|
||||||
|
|
||||||
|
start = utime.ticks_ms()
|
||||||
|
while utime.ticks_diff(utime.ticks_ms(), start) < 1500:
|
||||||
|
p.tick()
|
||||||
|
wdt.feed()
|
||||||
|
utime.sleep_ms(10)
|
||||||
|
|
||||||
|
p.set_param("pt", "off")
|
||||||
|
p.tick()
|
||||||
|
utime.sleep_ms(100)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
run()
|
||||||
|
|
||||||
|
|
||||||
34
test/patterns/color_transition.py
Normal file
34
test/patterns/color_transition.py
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import utime
|
||||||
|
from machine import WDT
|
||||||
|
from settings import Settings
|
||||||
|
from patterns import Patterns
|
||||||
|
|
||||||
|
|
||||||
|
def run():
|
||||||
|
s = Settings()
|
||||||
|
pin = s.get("led_pin", 10)
|
||||||
|
num = s.get("num_leds", 30)
|
||||||
|
|
||||||
|
p = Patterns(pin=pin, num_leds=num)
|
||||||
|
wdt = WDT(timeout=10000)
|
||||||
|
p.set_param("br", 64)
|
||||||
|
p.set_param("dl", 100)
|
||||||
|
p.set_param("cl", [(255, 0, 0), (0, 255, 0)])
|
||||||
|
p.set_param("pt", "color_transition")
|
||||||
|
|
||||||
|
start = utime.ticks_ms()
|
||||||
|
while utime.ticks_diff(utime.ticks_ms(), start) < 1500:
|
||||||
|
p.tick()
|
||||||
|
wdt.feed()
|
||||||
|
utime.sleep_ms(10)
|
||||||
|
|
||||||
|
p.set_param("pt", "off")
|
||||||
|
p.tick()
|
||||||
|
utime.sleep_ms(100)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
run()
|
||||||
|
|
||||||
|
|
||||||
34
test/patterns/color_wipe.py
Normal file
34
test/patterns/color_wipe.py
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import utime
|
||||||
|
from machine import WDT
|
||||||
|
from settings import Settings
|
||||||
|
from patterns import Patterns
|
||||||
|
|
||||||
|
|
||||||
|
def run():
|
||||||
|
s = Settings()
|
||||||
|
pin = s.get("led_pin", 10)
|
||||||
|
num = s.get("num_leds", 30)
|
||||||
|
|
||||||
|
p = Patterns(pin=pin, num_leds=num)
|
||||||
|
wdt = WDT(timeout=10000)
|
||||||
|
p.set_param("br", 64)
|
||||||
|
p.set_param("dl", 60)
|
||||||
|
p.set_param("cl", [(0, 0, 255), (255, 0, 0)])
|
||||||
|
p.set_param("pt", "color_wipe")
|
||||||
|
|
||||||
|
start = utime.ticks_ms()
|
||||||
|
while utime.ticks_diff(utime.ticks_ms(), start) < 1500:
|
||||||
|
p.tick()
|
||||||
|
wdt.feed()
|
||||||
|
utime.sleep_ms(10)
|
||||||
|
|
||||||
|
p.set_param("pt", "off")
|
||||||
|
p.tick()
|
||||||
|
utime.sleep_ms(100)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
run()
|
||||||
|
|
||||||
|
|
||||||
35
test/patterns/flicker.py
Normal file
35
test/patterns/flicker.py
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import utime
|
||||||
|
from machine import WDT
|
||||||
|
from settings import Settings
|
||||||
|
from patterns import Patterns
|
||||||
|
|
||||||
|
|
||||||
|
def run():
|
||||||
|
s = Settings()
|
||||||
|
pin = s.get("led_pin", 10)
|
||||||
|
num = s.get("num_leds", 30)
|
||||||
|
|
||||||
|
p = Patterns(pin=pin, num_leds=num)
|
||||||
|
wdt = WDT(timeout=10000)
|
||||||
|
p.set_param("br", 127)
|
||||||
|
p.set_param("dl", 100)
|
||||||
|
p.set_param("cl", [(255, 136, 0), (255, 136, 0)])
|
||||||
|
p.set_param("n1", 10)
|
||||||
|
p.set_param("pt", "flicker")
|
||||||
|
|
||||||
|
start = utime.ticks_ms()
|
||||||
|
while utime.ticks_diff(utime.ticks_ms(), start) < 1500:
|
||||||
|
p.tick()
|
||||||
|
wdt.feed()
|
||||||
|
utime.sleep_ms(10)
|
||||||
|
|
||||||
|
p.set_param("pt", "off")
|
||||||
|
p.tick()
|
||||||
|
utime.sleep_ms(100)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
run()
|
||||||
|
|
||||||
|
|
||||||
24
test/patterns/off.py
Normal file
24
test/patterns/off.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import utime
|
||||||
|
from machine import WDT
|
||||||
|
from settings import Settings
|
||||||
|
from patterns import Patterns
|
||||||
|
|
||||||
|
|
||||||
|
def run():
|
||||||
|
s = Settings()
|
||||||
|
pin = s.get("led_pin", 10)
|
||||||
|
num = s.get("num_leds", 30)
|
||||||
|
|
||||||
|
p = Patterns(pin=pin, num_leds=num)
|
||||||
|
wdt = WDT(timeout=10000)
|
||||||
|
p.set_param("pt", "off")
|
||||||
|
p.tick()
|
||||||
|
wdt.feed()
|
||||||
|
utime.sleep_ms(200)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
run()
|
||||||
|
|
||||||
|
|
||||||
34
test/patterns/on.py
Normal file
34
test/patterns/on.py
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import utime
|
||||||
|
from machine import WDT
|
||||||
|
from settings import Settings
|
||||||
|
from patterns import Patterns
|
||||||
|
|
||||||
|
|
||||||
|
def run():
|
||||||
|
s = Settings()
|
||||||
|
pin = s.get("led_pin", 10)
|
||||||
|
num = s.get("num_leds", 30)
|
||||||
|
|
||||||
|
p = Patterns(pin=pin, num_leds=num)
|
||||||
|
wdt = WDT(timeout=10000)
|
||||||
|
p.set_param("br", 64)
|
||||||
|
p.set_param("dl", 120)
|
||||||
|
p.set_param("cl", [(255, 0, 0), (0, 0, 255)])
|
||||||
|
p.set_param("pt", "on")
|
||||||
|
|
||||||
|
start = utime.ticks_ms()
|
||||||
|
while utime.ticks_diff(utime.ticks_ms(), start) < 800:
|
||||||
|
p.tick()
|
||||||
|
wdt.feed()
|
||||||
|
utime.sleep_ms(10)
|
||||||
|
|
||||||
|
p.set_param("pt", "off")
|
||||||
|
p.tick()
|
||||||
|
utime.sleep_ms(100)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
run()
|
||||||
|
|
||||||
|
|
||||||
36
test/patterns/pulse.py
Normal file
36
test/patterns/pulse.py
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import utime
|
||||||
|
from machine import WDT
|
||||||
|
from settings import Settings
|
||||||
|
from patterns import Patterns
|
||||||
|
|
||||||
|
|
||||||
|
def run():
|
||||||
|
s = Settings()
|
||||||
|
pin = s.get("led_pin", 10)
|
||||||
|
num = s.get("num_leds", 30)
|
||||||
|
|
||||||
|
p = Patterns(pin=pin, num_leds=num)
|
||||||
|
wdt = WDT(timeout=10000)
|
||||||
|
p.set_param("br", 255)
|
||||||
|
p.set_param("dl", 100)
|
||||||
|
p.set_param("cl", [(255, 255, 255), (255, 255, 255)])
|
||||||
|
p.set_param("n1", 200)
|
||||||
|
p.set_param("n2", 200)
|
||||||
|
p.set_param("pt", "pulse")
|
||||||
|
|
||||||
|
start = utime.ticks_ms()
|
||||||
|
while utime.ticks_diff(utime.ticks_ms(), start) < 1500:
|
||||||
|
p.tick()
|
||||||
|
wdt.feed()
|
||||||
|
utime.sleep_ms(10)
|
||||||
|
|
||||||
|
p.set_param("pt", "off")
|
||||||
|
p.tick()
|
||||||
|
utime.sleep_ms(100)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
run()
|
||||||
|
|
||||||
|
|
||||||
33
test/patterns/rainbow_cycle.py
Normal file
33
test/patterns/rainbow_cycle.py
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import utime
|
||||||
|
from machine import WDT
|
||||||
|
from settings import Settings
|
||||||
|
from patterns import Patterns
|
||||||
|
|
||||||
|
|
||||||
|
def run():
|
||||||
|
s = Settings()
|
||||||
|
pin = s.get("led_pin", 10)
|
||||||
|
num = s.get("num_leds", 30)
|
||||||
|
|
||||||
|
p = Patterns(pin=pin, num_leds=num)
|
||||||
|
wdt = WDT(timeout=10000)
|
||||||
|
p.set_param("br", 64)
|
||||||
|
p.set_param("dl", 100)
|
||||||
|
p.set_param("pt", "rainbow_cycle")
|
||||||
|
|
||||||
|
start = utime.ticks_ms()
|
||||||
|
while utime.ticks_diff(utime.ticks_ms(), start) < 1500:
|
||||||
|
p.tick()
|
||||||
|
wdt.feed()
|
||||||
|
utime.sleep_ms(10)
|
||||||
|
|
||||||
|
p.set_param("pt", "off")
|
||||||
|
p.tick()
|
||||||
|
utime.sleep_ms(100)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
run()
|
||||||
|
|
||||||
|
|
||||||
34
test/patterns/scanner.py
Normal file
34
test/patterns/scanner.py
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import utime
|
||||||
|
from machine import WDT
|
||||||
|
from settings import Settings
|
||||||
|
from patterns import Patterns
|
||||||
|
|
||||||
|
|
||||||
|
def run():
|
||||||
|
s = Settings()
|
||||||
|
pin = s.get("led_pin", 10)
|
||||||
|
num = s.get("num_leds", 30)
|
||||||
|
|
||||||
|
p = Patterns(pin=pin, num_leds=num)
|
||||||
|
wdt = WDT(timeout=10000)
|
||||||
|
p.set_param("br", 127)
|
||||||
|
p.set_param("dl", 50)
|
||||||
|
p.set_param("cl", [(0, 255, 0), (0, 255, 0)])
|
||||||
|
p.set_param("pt", "scanner")
|
||||||
|
|
||||||
|
start = utime.ticks_ms()
|
||||||
|
while utime.ticks_diff(utime.ticks_ms(), start) < 1500:
|
||||||
|
p.tick()
|
||||||
|
wdt.feed()
|
||||||
|
utime.sleep_ms(10)
|
||||||
|
|
||||||
|
p.set_param("pt", "off")
|
||||||
|
p.tick()
|
||||||
|
utime.sleep_ms(100)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
run()
|
||||||
|
|
||||||
|
|
||||||
34
test/patterns/theater_chase.py
Normal file
34
test/patterns/theater_chase.py
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import utime
|
||||||
|
from machine import WDT
|
||||||
|
from settings import Settings
|
||||||
|
from patterns import Patterns
|
||||||
|
|
||||||
|
|
||||||
|
def run():
|
||||||
|
s = Settings()
|
||||||
|
pin = s.get("led_pin", 10)
|
||||||
|
num = s.get("num_leds", 30)
|
||||||
|
|
||||||
|
p = Patterns(pin=pin, num_leds=num)
|
||||||
|
wdt = WDT(timeout=10000)
|
||||||
|
p.set_param("br", 64)
|
||||||
|
p.set_param("dl", 100)
|
||||||
|
p.set_param("cl", [(255, 255, 255), (0, 0, 0)])
|
||||||
|
p.set_param("pt", "theater_chase")
|
||||||
|
|
||||||
|
start = utime.ticks_ms()
|
||||||
|
while utime.ticks_diff(utime.ticks_ms(), start) < 1500:
|
||||||
|
p.tick()
|
||||||
|
wdt.feed()
|
||||||
|
utime.sleep_ms(10)
|
||||||
|
|
||||||
|
p.set_param("pt", "off")
|
||||||
|
p.tick()
|
||||||
|
utime.sleep_ms(100)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
run()
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user