Created
August 11, 2020 19:10
-
-
Save FoamyGuy/92d69e0681a0d08eb98263372e8b1271 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import supervisor | |
import time | |
import board | |
# For Trinket M0, Gemma M0, ItsyBitsy M0 Express, and ItsyBitsy M4 Express | |
import adafruit_dotstar | |
led = adafruit_dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2) | |
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[0] = (255,0,0) | |
def turn_blue(): | |
led[0] = (0,0,255) | |
def turn_green(): | |
led[0] = (0,255,0) | |
def turn_green(): | |
led[0] = (0,255,0) | |
def turn_color(color): | |
led[0] = 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: | |
print("failed: %s" % value) | |
while True: | |
serial_read() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment