Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
unicorn_server.py
from flask import Flask
app = Flask(__name__)
import unicornhat as UH
import time
import os
import signal
import sys
def clear_uh():
UH.clear()
UH.show()
def sigterm_handler(_signo, _stack_frame):
clear_uh()
sys.exit(0)
max_pixels = 8
signal.signal(signal.SIGTERM, sigterm_handler)
def on(column, r, g, b):
x = column
for y in range(0, max_pixels):
UH.set_pixel(x, y, r, g, b)
UH.show()
sleep_for = 0.25
@app.route('/red')
def blink_red():
for i in range(0,8):
on(i, 255, 0, 0)
time.sleep(sleep_for)
clear_uh()
return 'Blinking red!'
@app.route('/')
def blink():
for i in range(0,8):
on(i, 0, 0, 255)
time.sleep(sleep_for)
clear_uh()
return 'Blinking!'
if __name__ == '__main__':
app.run(host="0.0.0.0", port=5000, debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.