diff --git a/README.md b/README.md index 5438ab5..09ddd23 100644 --- a/README.md +++ b/README.md @@ -150,7 +150,7 @@ MicroPython on the ESP32 has virtual timers and 4 hardware timers. You can use a Timers execute a callback, which takes the timer as an argument ``` python -from machine import Timer +from machine import Timer, Pin import utime # Create a virtual timer with ID -1. @@ -160,10 +160,13 @@ timer = Timer(-1) data = [0] * 32 index = 0 +led = Pin(5, Pin.OUT) + def callback(timer): global data, index data[index] = utime.ticks_ms index = (index + 1) % 32 + led(!led()) # Run the callback once, after 100 ms timer.init(mode = Timer.ONE_SHOT, period = 100, callback = callback)