Skip to content

Commit

Permalink
Create ColorPal_Test.py
Browse files Browse the repository at this point in the history
Proof of concept for the ColorPal connected to the micro:bit added to the dev folder.
  • Loading branch information
AndyLindsay committed May 11, 2019
1 parent 283d382 commit ee296ef
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions Dev/Tests/ColorPal_Test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# ColorPal_Test.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 *

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)
print("r = %d, g = %d, b = %d" % (r, g, b))

0 comments on commit ee296ef

Please sign in to comment.