Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Deep Fried Neurons Happy Hour Micro-expression to Macro-expression LED headband
#
# 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