Created
June 17, 2020 19:26
-
-
Save FoamyGuy/1556e3874f6a1d1f748881c347b33072 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 | |
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