Created
June 26, 2020 21:32
-
-
Save todbot/9da991493158a85be1fe9aac1fd3f5f5 to your computer and use it in GitHub Desktop.
Deep Fried Neurons Happy Hour Micro-expression to Macro-expression LED headband
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
# | |
# Deep Fried Neurons Happy Hour | |
# Micro-expression to Macro-expression LED headband | |
# @todbot 2020 | |
# | |
import time | |
import board | |
import neopixel | |
import supervisor | |
import sys | |
import time | |
# Configure | |
PIXEL_PIN = board.D1 # pin that the NeoPixel is connected to | |
ORDER = neopixel.GRB # pixel color channel order | |
COLOR = (100, 50, 150) # color to blink | |
CLEAR = (0, 0, 0) # clear (or second color) | |
DELAY = 0.5 # blink rate in seconds | |
pixels = neopixel.NeoPixel(PIXEL_PIN, 3, pixel_order=ORDER) | |
pixels.brightness = 0.25 | |
pindex = 0 # index into pixel array of LED to actuate | |
def serial_read_pindex(): | |
global pindex | |
value = "" | |
if supervisor.runtime.serial_bytes_available: | |
value = sys.stdin.read(1) | |
if value: | |
print("read char:",value) | |
try: | |
pindex = int(value) - 1 | |
except ValueError: | |
print("not a number") | |
ledTime = time.monotonic() | |
# Loop forever and blink the color | |
while True: | |
# print("hi") | |
# if we have a good pindex, use it | |
if pindex >= 0 and pindex < 3: | |
ledTime = time.monotonic() | |
pixels[pindex] = COLOR | |
pindex = -1 # off | |
# turn off LED after 1 second | |
if time.monotonic() - ledTime > 1.0: | |
pixels.fill(0) | |
serial_read_pindex() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment