I am integrating a Unicorn HAT Mini in to a larger bit of code with timing, audio, buttons etc.
I’m using Twisted for looping calls.
For the Unicorn HAT Mini I’m essentially using this code.
My code
def minuteCheck():
# Do some stuff once a minute like checking the time and triggering audio and visual items
def screenUpdate():
# This is the loop where I update the screen. I do a version of the code in the github above.
# Setup screen bla bla bla
for y in range(display_height):
for x in range(display_width):
if image.getpixel((x + offset_x, y)) == 255:
unicornhatmini.set_pixel(x, y, 255, 255, 255)
else:
unicornhatmini.set_pixel(x, y, 0, 0, 0)
unicornhatmini.show()
# once a minute
loopMinuteCheck = LoopingCall(minuteCheck)
loopMinuteCheck.start(60)
# loop every 0.5s to update screen
loopScreenCheck = LoopingCall(screenUpdate)
loopScreenCheck.start(0.5)
# go!
logger.debug("Starting Twisted")
reactor.run()
This doesn’t work.
The screen update will not work without a While True: surrounding the screen code.
How can I do this screen update and show the text, without using While loops and time.sleeps?