Code: Select all
def light(led):
led.toggle()
import pyb
led = pyb.LED(4)
tim = pyb.Timer(1, freq=1) # freq in Hz
tim.callback(light(led))
Code: Select all
def light(led):
led.toggle()
import pyb
led = pyb.LED(4)
tim = pyb.Timer(1, freq=1) # freq in Hz
tim.callback(light(led))
Code: Select all
def light(led):
def light_callback(tim):
led.toggle()
return light_callback
tim = pyb.Timer(1, freq=1)
tim.callback(light(led))
Code: Select all
import pyb
def light(tim):
led = pyb.LED(4)
led.toggle()
tim = pyb.Timer(1, freq=10) # freq in Hz
tim.callback(light)
It allows the same timer callback to be used for multiple timers, and the callback can then distinguish which timer its being called for.Andrew1234 wrote: ↑Thu Mar 03, 2022 9:27 pmHi Dave
I adjusted the code based on your response and the example you provided as below:
This now works as expected. I left led as a local variable for now.Code: Select all
import pyb def light(tim): led = pyb.LED(4) led.toggle() tim = pyb.Timer(1, freq=10) # freq in Hz tim.callback(light)
I'm a little confused about the function light needing a parameter of the timer object. Is this just the way to properly connect the callback to the function?