WiPy Timer
Posted: Tue Nov 29, 2016 10:40 pm
Hello, i found numerous questions here about the WiPy timer class, but most of them was before the 1.6 release. However i still couldn't make it work. I have a wipy with the latest framework(1.8.2). I tried all the examples from the docs, here are my tries:
[CODE]
from machine import Timer
from machine import Pin
tim = Timer(1, mode=Timer.PERIODIC, width=32)
tim_a = tim.channel(Timer.A | Timer.B, freq=1) # 1 Hz frequency requires a 32 bit timer
def tick(timer): # we will receive the timer object when being called
f = open('abc.txt', 'w')
f.write('it_works')
f.close() # toggle the LED
print('timerTicked')
tim_a.irq(handler=tick, trigger=Timer.TIMEOUT)
[/CODE]
[CODE]
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) # toggle a LED on every cycle of the timer
[/CODE]
I tried the other basic examples also, none of them seemed to work for me, but i dont get any errors either, could someone help me out?
[CODE]
from machine import Timer
from machine import Pin
tim = Timer(1, mode=Timer.PERIODIC, width=32)
tim_a = tim.channel(Timer.A | Timer.B, freq=1) # 1 Hz frequency requires a 32 bit timer
def tick(timer): # we will receive the timer object when being called
f = open('abc.txt', 'w')
f.write('it_works')
f.close() # toggle the LED
print('timerTicked')
tim_a.irq(handler=tick, trigger=Timer.TIMEOUT)
[/CODE]
[CODE]
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) # toggle a LED on every cycle of the timer
[/CODE]
I tried the other basic examples also, none of them seemed to work for me, but i dont get any errors either, could someone help me out?