Page 2 of 2

Re: object-oriented programming

Posted: Mon Apr 27, 2015 7:56 am
by mschulz
With an other pins it works,

But the switch callback

Code: Select all

# USR Schalter
print ('INIT des Schalters')
switch = pyb.Switch()

def switchcallback():
    print('INFO-Switch: Switch Callback aufgerufen!')

switch.callback(lambda :switchcallback())
only starts one time.

Which is the best solution to stop the scheduler with a push button (the USR or an hardware interrupt (a button I can braze on other pins)
(and restart it)

Re: object-oriented programming

Posted: Thu Apr 19, 2018 4:49 pm
by dhylands
You can pass switchcallback directly to the callback function.

What you coded:

Code: Select all

switch.callback(lambda :switchcallback())
is equivalent to:

Code: Select all

x = switchcallback()
switch.callback(lamba: x)
You can code it like this:

Code: Select all

switch.callback(switchcallback)
Note that there are no parenthesis so it passes in the address of the function whereas with the parenthesis it calls the function.