Code: Select all
import pyb
t_4 = pyb.Timer(4)
t_4.init(freq=1)
t_4.callback(lambda t: pyb.LED(4).toggle())
It even works if I wrap it in a simple toggle function (I believe the restraint is callback() has to be given a function with 1 arg):
Code: Select all
def toggleLed(n_led):
pyb.LED(n_led).toggle()
Code: Select all
def ledHeartbeat(n_led):
for i in [1,2]:
pyb.LED(n_led).toggle()
pyb.delay(100)
pyb.LED(n_led).toggle()
pyb.delay(100)
I can verify it gives the 'heartbeat' I'm looking for by running:
Code: Select all
for m in [1,2,3,4,5,6,7,8]:
ledHeartbeat(4)
pyb.delay(1000)
Code: Select all
lambda t:
I was thinking that, perhaps, if the callback() doesn't return before the function is through, it could create problems, but I'm pretty sure the cumulative 400ms of delay + toggle code will complete in 1 second. Any ideas on why I'm seeing this behavior? Thanks in advance for your replies.