For example, with a timer event source, the typical 'hello world' example:
Code: Select all
led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT
while True:
led.value = True
time.sleep(0.5)
led.value = False
time.sleep(0.5)
Code: Select all
led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT
ev = time.every(interval=0.5)
while True:
e = waitevent()
if isinstance(e, ev):
led.value = not led.value
The benefit of this is it is a lot easier for the beginner to move forward from this starting point. For example you can trivially add a second LED flashing at a different rate, which is conceptually and practically quite difficult at present.
Another benefit is that there no longer needs to be a 'busy loop' - if the hardware allows it, the underlying timer can be interrupt driven with the processor automatically put in a low power mode until the timer expires. The keypad event system can be merged into the same event queue, and event support can also be added to other libraries as appropriate.