-
Notifications
You must be signed in to change notification settings - Fork 0
/
Seeker.py
86 lines (72 loc) · 2.56 KB
/
Seeker.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from microbit import *
import radio
# Start the radio on channel 1
channel = 1
radio.config(group=channel)
radio.on()
display.show(channel)
sleep(600)
while True:
#################################################################
# Add code below to send a message using the radio, when
# button B is pressed.
#
# Start by sending "Santa" to the micro:bit on channel 1 (stick person)
# then, send the response to the micro:bit using channel 2.
# Do the same for the micro:bits on channels 3 and 4, then come
# and tell me the answer to the final riddle!
#
#################################################################
####### Don't change the code below this line #######
# Change the channel when button A is pressed
if button_a.was_pressed():
channel += 1
if channel == 5: channel = 1
radio.config(group=channel)
display.show(channel)
sleep(600)
# Check the strength of any received messages
received_messages = []
received = None
while True:
received = radio.receive_full()
if not received:
break
received_messages.append(received)
# Check if we recieved any messages
if len(received_messages) == 0:
display.show(Image('00000:'
'00000:'
'00000:'
'00000:'
'99999'))
else:
# Find the average signal strength of all the messages
average_rssi = sum([m[1] for m in received_messages]) / len(received_messages)
if average_rssi > -55:
display.show(Image('99999:'
'99999:'
'99999:'
'99999:'
'99999'))
elif average_rssi > -65:
display.show(Image('00000:'
'99999:'
'99999:'
'99999:'
'99999'))
elif average_rssi > -80:
display.show(Image('00000:'
'00000:'
'99999:'
'99999:'
'99999'))
else:
display.show(Image('00000:'
'00000:'
'00000:'
'99999:'
'99999'))
sleep(700)
display.clear()
sleep(300)