-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
84 lines (82 loc) · 2.56 KB
/
main.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
def on_microbit_id_button_a_evt():
if input.magnetic_force(Dimension.STRENGTH) < 0 and input.magnetic_force(Dimension.STRENGTH) < 20:
basic.show_leds("""
. . . . .
. . . . .
. . . . .
. . . . .
# # # # #
""")
elif input.magnetic_force(Dimension.STRENGTH) > 20 and input.magnetic_force(Dimension.STRENGTH) < 40:
basic.show_leds("""
. . . . .
. . . . .
. . . . .
# # # # #
# # # # #
""")
elif input.magnetic_force(Dimension.STRENGTH) > 40 and input.magnetic_force(Dimension.STRENGTH) < 60:
basic.show_leds("""
. . . . .
. . . . .
# # # # #
# # # # #
# # # # #
""")
elif input.magnetic_force(Dimension.STRENGTH) > 60 and input.magnetic_force(Dimension.STRENGTH) < 80:
basic.show_leds("""
. . . . .
# # # # #
# # # # #
# # # # #
# # # # #
""")
elif input.magnetic_force(Dimension.STRENGTH) > 80 and input.magnetic_force(Dimension.STRENGTH) < 100:
basic.show_leds("""
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
""")
else:
basic.show_leds("""
# . # . #
# . # . #
# . # . #
. . . . .
# . # . #
""")
control.on_event(EventBusSource.MICROBIT_ID_BUTTON_A,
EventBusValue.MICROBIT_EVT_ANY,
on_microbit_id_button_a_evt)
basic.show_string("MAGNET METER")
basic.show_leds("""
. # . # .
. # . # .
. . . . .
# . . . #
. # # # .
""")
control.wait_micros(48)
basic.clear_screen()
basic.show_leds("""
. # # # .
# . . . #
# # # # #
# . . . #
# . . . #
""")
control.raise_event(EventBusSource.MICROBIT_ID_BUTTON_A,
EventBusValue.MICROBIT_EVT_ANY)
def on_forever():
if input.button_is_pressed(Button.AB):
basic.show_leds("""
# # # # #
# . . . .
# . # . #
# . . . .
# # # # #
""")
music.play_melody("E F G A G - B C5 ", 500)
basic.forever(on_forever)