Skip to content

Instantly share code, notes, and snippets.

@FoamyGuy
Created June 17, 2020 19:26
Show Gist options
  • Save FoamyGuy/1556e3874f6a1d1f748881c347b33072 to your computer and use it in GitHub Desktop.
Save FoamyGuy/1556e3874f6a1d1f748881c347b33072 to your computer and use it in GitHub Desktop.
import supervisor
import time
import board
# For Trinket M0, Gemma M0, ItsyBitsy M0 Express, and ItsyBitsy M4 Express
import adafruit_dotstar
import neopixel
#led = adafruit_dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1)
led = neopixel.NeoPixel(board.D2, 30, auto_write=True)
def convert_color_str(color_str):
color_str = color_str.replace("(", "")
color_str = color_str.replace(")", "")
parts = color_str.split(",")
color_tuple = tuple(int(s) for s in parts)
return color_tuple
def turn_red():
led.fill((255,0,0))
def turn_blue():
led.fill((0,0,255))
def turn_green():
led.fill((0,255,0))
def turn_green():
led.fill((0,255,0))
def turn_color(color):
led.fill(convert_color_str(color))
COMMAND_MAP = {
"red": turn_red,
"blue": turn_blue,
"green": turn_green,
"color": turn_color
}
def serial_read():
if supervisor.runtime.serial_bytes_available:
value = input()
print("you sent: %s" % value)
parts = value.split(" ")
if parts[0] in COMMAND_MAP.keys():
try:
if len(parts) > 1:
COMMAND_MAP[parts[0]](parts[1])
else:
COMMAND_MAP[parts[0]]()
except Exception as e:
print("failed: %s" % value)
print(e)
while True:
serial_read()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment