-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
64 lines (48 loc) · 1.3 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
import microbit
from microbit import display, Image, button_a
# The event loop
def event_loop(tasks):
run_queue = [t() for t in tasks if t is not None]
while run_queue:
t = run_queue.pop(0)
try:
next(t)
run_queue.append(t)
except StopIteration:
pass
# Wrappers for the standard library
def sleep(msecs):
t = microbit.running_time()
while microbit.running_time() < t + msecs:
yield
def wait_for_button_press(button):
while not button.is_pressed():
yield
def scroll(string, delay=150, loop=False, monospace=False):
display.scroll(string, delay, wait=False,
loop=loop, monospace=monospace)
yield from sleep(delay * 5 * (len(string) + 1))
# Initializing Skynet
def task_1():
display.show(Image.CLOCK1)
yield from sleep(2000)
display.show(Image.CLOCK3)
yield from sleep(2000)
display.show(Image.CLOCK5)
def task_2():
yield from sleep(1000)
display.show(Image.CLOCK2)
yield from sleep(2000)
display.show(Image.CLOCK4)
yield from sleep(2000)
display.show(Image.CLOCK6)
def task_3():
yield from wait_for_button_press(button_a)
yield from scroll('The end')
display.scroll('---')
tasks = [
task_1,
task_2,
task_3
]
event_loop(tasks)