From 031759ff7c3ca2151b35de0e1cd9bbb99987aff3 Mon Sep 17 00:00:00 2001 From: Valentin Ochs Date: Mon, 25 Nov 2019 18:25:01 +0100 Subject: [PATCH] Add LED to timer example --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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)