Skip to content

Instantly share code, notes, and snippets.

@kjagiello
Last active July 21, 2016 11:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kjagiello/1352e5989278f75fe8efa0b263c28a10 to your computer and use it in GitHub Desktop.
Save kjagiello/1352e5989278f75fe8efa0b263c28a10 to your computer and use it in GitHub Desktop.
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