test allowing more than one light change per tick
This commit is contained in:
parent
fe0d9991bd
commit
9da07501ba
1 changed files with 7 additions and 3 deletions
|
@ -4,15 +4,16 @@ import board
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
def defaultPattern(n, t):
|
def defaultPattern(n, t):
|
||||||
return (255, 0, 200)
|
return (0, 0, 255)
|
||||||
|
|
||||||
class LightStrip:
|
class LightStrip:
|
||||||
def __init__(self, data_pin = board.D18, string_length = 300, brightness = 1, pixel_order = neopixel.GRB):
|
def __init__(self, data_pin = board.D18, string_length = 300, brightness = 1, pixel_order = neopixel.GRB, max_changes = 5):
|
||||||
self.data_pin = data_pin
|
self.data_pin = data_pin
|
||||||
|
|
||||||
self.np = neopixel.NeoPixel(self.data_pin, string_length, brightness = brightness, auto_write=True, pixel_order = pixel_order)
|
self.np = neopixel.NeoPixel(self.data_pin, string_length, brightness = brightness, auto_write=True, pixel_order = pixel_order)
|
||||||
self.pattern = defaultPattern
|
self.pattern = defaultPattern
|
||||||
self.cur_tick = 0
|
self.cur_tick = 0
|
||||||
|
self.max_changes = max_changes
|
||||||
|
|
||||||
def set_light_level(self, level):
|
def set_light_level(self, level):
|
||||||
self.np.brightness = level
|
self.np.brightness = level
|
||||||
|
@ -23,11 +24,14 @@ class LightStrip:
|
||||||
np = self.np
|
np = self.np
|
||||||
t = self.cur_tick
|
t = self.cur_tick
|
||||||
n = np.n
|
n = np.n
|
||||||
|
changes = 0
|
||||||
for i in range(n):
|
for i in range(n):
|
||||||
col = self.pattern(i, t)
|
col = self.pattern(i, t)
|
||||||
logging.debug("TEST VALUES: np {} col {} same {}".format(np[i], col, tuple(np[i]) != col))
|
logging.debug("TEST VALUES: np {} col {} same {}".format(np[i], col, tuple(np[i]) != col))
|
||||||
if tuple(np[i]) != col:
|
if tuple(np[i]) != col:
|
||||||
|
changes = changes + 1
|
||||||
np[i] = col
|
np[i] = col
|
||||||
logging.debug("CHANGE COLOR OF PIXEL {} TO {} ON TICK {}".format(i, col, t))
|
logging.debug("CHANGE COLOR OF PIXEL {} TO {} ON TICK {}".format(i, col, t))
|
||||||
|
if changes >= self.max_changes:
|
||||||
break;
|
break;
|
||||||
self.cur_tick = t + 1
|
self.cur_tick = t + 1
|
Loading…
Reference in a new issue