Last active
July 21, 2016 11:47
-
-
Save kjagiello/1352e5989278f75fe8efa0b263c28a10 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import microbit | |
from microbit import display, Image | |
def sleep(msecs): | |
t = microbit.running_time() | |
while microbit.running_time() < t + msecs: | |
yield | |
# The event loop | |
def run_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 | |
# 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 sleep(6000) | |
display.scroll('The end') | |
tasks = [ | |
task_1, | |
task_2, | |
task_3 | |
] | |
run_event_loop(tasks) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment