From 21532c1ef886fa36879173e540cf8330800b1b36 Mon Sep 17 00:00:00 2001 From: Jane Petrovna Date: Thu, 12 Nov 2020 04:48:19 -0500 Subject: [PATCH] t --- light_manager.py | 2 +- pattern.py | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/light_manager.py b/light_manager.py index 50eb6d0..897c19e 100644 --- a/light_manager.py +++ b/light_manager.py @@ -10,7 +10,7 @@ def defaultPattern(n, t, pv): class LightStrip: - def __init__(self, data_pin=board.D18, string_length=300, brightness=1, pixel_order=neopixel.GRB, max_changes=5): + def __init__(self, data_pin=board.D18, string_length=300, brightness=0.7, pixel_order=neopixel.GRB, max_changes=5): self.data_pin = data_pin self.np = neopixel.NeoPixel( diff --git a/pattern.py b/pattern.py index 2a65d73..78ecc3e 100644 --- a/pattern.py +++ b/pattern.py @@ -21,7 +21,9 @@ this.values = { "g": 0, "b": 0, "tick": 0, - "index": 0 + "index": 0, + "fadeval": 0, + "fadeinc": True } @@ -51,6 +53,20 @@ def mod(target, arg, index): return (target % arg, index) +def fade(target, arg, index): + value = this.values['fadeval'] + if this.values['fadeinc']: + value += 1 + if value >= arg: + this.values['fadeinc'] = False + else: + value -= 1 + if value <= 0: + this.values['fadeinc'] = True + this.values['fadeval'] = value + return (value, index) + + def rand(target, arg, index): return (random.randrange(0, 255), index) @@ -110,6 +126,7 @@ this.instructions = { "MULTIPLY": mult, "DIVIDE": div, "MODULO": mod, + "FADE": fade, "RANDOM": rand, "JMP": jmp, "JNZ": jnz,