I’m using a Blinkt! and pi Zero W to create a means to indicate when my various home automation bits are in certain states (wemo switches and plugs on, garage door open, etc…)
Everything works fine when I’ve got one script running, but when I run another that is controlling a different set of LEDs, things get unpredictable. LEDs come on w/ different brightnesses and colors, unpredictable durations, etc. I thought that putting everything in one script may be helpful in case there was some initialization process that was messing with things, but this yields some crazy results as well. Here’s the code I wrote to have a simple test case that I thought had the best chance of showing that it was something that I was doing - 2 functions controlling 2 different groups of LEDs, running in parallel:
from time import sleep from threading import Thread from blinkt import set_pixel, show def red(): while True: for l in range(0,4,1): set_pixel(l, 1, 0, 0) show() sleep(.25) for l in range(3,-1,-1): set_pixel(l, 0, 0, 0) show() sleep(.25) def blue(): while True: for l in range(4,8,1): set_pixel(l, 0, 0, 1) show() sleep(.25) for l in range(7,3,-1): set_pixel(l, 0, 0, 0) show() sleep(.25) if __name__ == '__main__': Thread(target = red).start() Thread(target = blue).start()
Things sometimes start out as I’d expect, but get crazy eventually…Any thoughts on how I can make this work? Is my only option to write a single function to deal with LEDs, and feed information on what should be lit from others?
Thanks in advance!