Skip to content

Commit

Permalink
Create ColorPal_Test_and_LED_Graph.py
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyLindsay committed May 11, 2019
1 parent ee296ef commit dcb98fa
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions Dev/Tests/ColorPal_Test_and_LED_Graph.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# ColorPal_Test_and_LED_Graph.py

# IMPORTANT: Connect directly to the micro:bit's pin2 and pin1.

# diode
# 0.7 V
# pin2 -- anode
# pin1 -- cahtode -- colorpal signal

from cyberbot import *
from microbit import display

bot(22).tone(2000, 200)

while True:
pin1.write_digital(0)
sleep(10)
pin1.read_digital()
while pin2.read_digital() == 0:pass
pin1.write_digital(0)
sleep(80)
pin1.read_digital()
sleep(10)
uart.init(baudrate=4800, tx=pin1, rx=pin2)
c=b'=(00 $ m)!'
uart.write(c)
sleep(10)
if uart.any():
val = uart.read()
sleep(120)
val = uart.read()
uart.init(115200)
if val is not None:
i = val.find(b'$')
r = int(val[i+1:i+4],16)
g = int(val[i+4:i+7], 16)
b = int(val[i+7:i+10],16)
for row in range(0, 5):
if (r//(50*(row+1))) > 0:bright=5
else:bright=0
display.set_pixel(4, row, bright)
if (g//(50*(row+1))) > 0:bright=5
else:bright=0
display.set_pixel(2, row, bright)
if (b//(50*(row+1))) > 0:bright=5
else:bright=0
display.set_pixel(0, row, bright)
print("r = %d, g = %d, b = %d" % (r, g, b))

0 comments on commit dcb98fa

Please sign in to comment.