Code: Select all
from machine import Timer
tim = Timer(4) # create a timer object using timer 4
tim.init(mode=Timer.PERIODIC) # initialize it in periodic mode
tim_ch = tim.channel(Timer.A, freq=2) # configure channel A at a frequency of 2Hz
tim_ch.callback(handler=lambda t:led.toggle()) # toggle a LED on every cycle of the timer
Code: Select all
led = Pin('GP25', machine.Pin.OUT)
But that example doesn't work:
Code: Select all
>>> tim_ch = tim.channel(Timer.A, freq=2)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid argument(s) value