-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.py
More file actions
54 lines (47 loc) · 1.36 KB
/
Copy pathcode.py
File metadata and controls
54 lines (47 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import supervisor
import usb_cdc
import time
import json
import neopixel
import board
import sys
import math
PIXEL_PIN = board.GP16
NUMBER_OF_PIXELS = 30
ORDER = neopixel.GRB
neo = neopixel.NeoPixel(
PIXEL_PIN, NUMBER_OF_PIXELS, brightness=0.5, auto_write=False, pixel_order=ORDER)
neo.fill((0, 0, 0))
neo.show()
print("listening...")
serial = sys.stdin
offset = -1
height = 0
while True:
neo.fill((10, 10, 10))
if supervisor.runtime.serial_bytes_available:
data_in = serial.readline()
data = None
if data_in:
try:
data = json.loads(data_in)
except ValueError:
data = {"raw": data_in}
if isinstance(data, dict):
if "x" in data:
try:
neo[int(data["x"]/64)-(2-offset)] = (64, 64, 64)
neo[int(data["x"]/64)-(1-offset)] = (127, 127, 127)
neo[int(data["x"]/64)+offset] = (255, 255, 255)
neo[int(data["x"]/64)+(1+offset)] = (127, 127, 127)
neo[int(data["x"]/64)+(2+offset)] = (64, 64, 64)
except:
pass
if "key" in data:
try:
height = int(data["key"])
except:
pass
neo.show()
height += .01
time.sleep(0.001)