-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.py
42 lines (34 loc) · 924 Bytes
/
code.py
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
from adafruit_circuitplayground import cp
import supervisor
import time
import sys
import random
def non_blocking_read():
rgb_s = []
s = ""
while supervisor.runtime.serial_bytes_available and s != '\n':
s = sys.stdin.read(1)
rgb_s.append(s)
return ''.join(rgb_s).strip()
def parse_inp(s):
return [tuple(int(p) for p in t.split(' ')) for t in s.split(',')]
def light_up(rgb_out):
# TODO: Varying brightness
cp.pixels.brightness = 0.01
cp.pixels[:] = rgb_out
def ran():
return random.randint(0,255)
def random_rgb():
return ','.join([
' '.join(str(ran())
for _ in range(3))
for x in range(10)
])
while True:
# print('circuit-cinema')
#light_up(parse_inp((random_rgb())))
# time.sleep(0.5)
output = non_blocking_read()
if output:
print(repr(output), end='-------')
light_up(parse_inp((output)))