How to use a Timer to blink a LED
-
Hi there,
I've followed following example form "5. Hardware Timers" with no success
from machine import Timer
from machine import Pin
led = Pin('GP16', mode=Pin.OUT) # enable GP16 as output to drive the LED
tim = Timer(3) # create a timer object using timer 3
tim.init(mode=Timer.PERIODIC) # initialize it in periodic mode
tim_ch = tim.channel(Timer.A, freq=5) # configure channel A at a frequency of 5Hz
tim_ch.irq(handler=lambda t:led.toggle(), trigger=Timer.TIMEOUT)If I type every line into the REPL, I got following error...
from machine import Timer
from machine import Pin
led = Pin('G16', mode=Pin.OUT)
tim = Timer(3)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: cannot create 'Timer' instancesNow, if I follow the example under "Quick reference for the WiPy" (which is different to previous one!!!)...
from machine import Timer
from machine import Pin
tim = Timer(0, mode=Timer.PERIODIC)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: type object 'Timer' has no attribute 'PERIODIC'I would appreciate any help in regards to:
- Has anyone found a Timer Tutorial here?
- What is wrong with the snip codes that I 've pasted?
Cheers
ColombianAus -
You're following the documentation for WiPy 1 but you have the new WiPy 2 which does Timers differently.
All the new documentation is at https://docs.pycom.io
The section you want is at https://docs.pycom.io/pycom_esp32/pycom_esp32/tutorial/includes/timers.html
Use the Alarm example
-
thank you mate...spot on. ...Do you know what is the most recent copy "Micropython Documentation"? for WiPy 2.0?
cheers
ColombianAus
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login