Duplex communication
[microbit.git] / radio_test / radio_receive.py
1 from microbit import *
2 import radio
3
4 A_IMAGE = Image('00009:'
5 '09990:'
6 '90090:'
7 '90090:'
8 '09999')
9
10 B_IMAGE = Image('90009:'
11 '90000:'
12 '99900:'
13 '90090:'
14 '99900')
15
16 radio.on()
17
18 display.scroll('Ready', wait=False, loop=True)
19 last_receive_time = None
20 display_image = None
21
22 while True:
23 message = radio.receive()
24 if message:
25 last_receive_time = running_time()
26 if message == 'a':
27 display_image = A_IMAGE
28 if message == 'b':
29 display_image = B_IMAGE
30 elif last_receive_time:
31 dimness = (running_time() - last_receive_time) / 500
32 if dimness > 9: dimness = 9
33 display.show(display_image / dimness , wait=False)