using lambda with timer

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
AlexBir
Posts: 7
Joined: Tue Apr 23, 2019 1:00 pm

using lambda with timer

Post by AlexBir » Fri Apr 26, 2019 8:44 pm

Hi,

Code: Select all

def blink_led():
    pyb.LED(1).toggle()



tim=pyb.Timer(4)
tim.init(freq=2)
tim.callback(blink_led)




I am getting:


PYB: sync filesystems
PYB: soft reboot
MicroPython v1.9.4-85-gdf9b7e8f on 2018-05-24; PYBv1.1 with STM32F405RG
Type "help()" for more information.
>>> uncaught exception in Timer(4) interrupt handler
TypeError:



why?

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: using lambda with timer

Post by dhylands » Fri Apr 26, 2019 9:39 pm

Because your callback is missing a parameter.

The documentation for the timer callback is here:
http://docs.micropython.org/en/latest/l ... l.callback
Your callback must take one argument, which is the timer object.

You can also use lambda functions like this example here:
http://docs.micropython.org/en/latest/p ... -callbacks
which takes one argument (the t)

You can also get more information about the error by allocating an emergency exception buffer as described here:
http://docs.micropython.org/en/latest/r ... ion-buffer

Post Reply