forked from danicampora/Micropython-scheduler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroundrobin.py
31 lines (24 loc) · 842 Bytes
/
roundrobin.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
# roundrobin.py Runs three threads in round robin fashion. Stops after a duration via a timeout thread.
# Author: Peter Hinch
# Copyright Peter Hinch 2016 Released under the MIT license
from usched import Sched
# Run on MicroPython board bare hardware
# THREADS:
def stop(fTim, objSch): # Stop the scheduler after fTim seconds
yield fTim
print('Stopping')
objSch.stop()
def robin(text):
while True:
print(text)
yield
# USER TEST PROGRAM
def test(duration = 0):
objSched = Sched(True, 1) # heartbeat on LED 1
objSched.add_thread(robin("Thread 1"))
objSched.add_thread(robin("Thread 2"))
objSched.add_thread(robin("Thread 3"))
if duration:
objSched.add_thread(stop(duration, objSched)) # Kill after a period
objSched.run()
test(5)