Created
June 29, 2018 22:03
-
-
Save bveina/bc307701975d84c10f96e75e477f4a88 to your computer and use it in GitHub Desktop.
the basic framework for multithreaded control of led strips.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clock = Pin(14,Pin.OUT) #wemos D5 | |
data = Pin(13,Pin.OUT) #wemos D7 | |
numPixels=20 | |
apa = APA102(clock,data,numPixels) | |
seg1 = Segment(apa,0,9,Segment.dotScan,rainbow,2000,False) # outer ring | |
seg2 = Segment(apa,10,19,Segment.blink,primary,2000,False) # inner ring | |
lock_instance=Lock() | |
event1 = Event() | |
Event2 = Event() | |
Event2.set(); | |
async def handle(seg,lock): | |
global drift | |
global localEpoc | |
t1=0 | |
t2=0 | |
while(1): | |
async with lock: | |
t=seg.operate() | |
event1.set() | |
await asyncio.sleep_ms(t) | |
async def redraw(strip,lock): | |
while 1: | |
await event1 | |
async with lock: | |
strip.write() | |
event1.clear() | |
def test(): | |
loop = asyncio.get_event_loop() | |
for s in [seg1,seg2]: | |
loop.create_task(handle(s,lock_instance)) | |
loop.create_task(redraw(apa,lock_instance)) | |
loop.create_task(monitorUDP(lock_instance)) | |
loop.run_forever() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment