something like GPIO.add_event_detect(23, GPIO.RISING , callback=ssEchoHandler, args=(arg1,))
Thanks!!!
Code: Select all
cb = lambda arg1=valueToPass: functionToCall(arg1)
GPIO.add_event_callback(channel, cb, bouncetime=200)
This is the answer! Thanks!!!scotty101 wrote:The documentation doesn't answer the OPs question.
I suspect you'd have to use lamba function to add arguments to the callback. The below code won't work but it might get you somewhere.
Code: Select all
cb = lambda arg1=valueToPass: functionToCall(arg1) GPIO.add_event_callback(channel, cb, bouncetime=200)
Code: Select all
cb = lambda channel, arg1=valueToPass: functionToCall(arg1)
GPIO.add_event_callback(channel, cb, bouncetime=200)Code: Select all
a = lambda x=2: type(x)
a("Hello")
=> <type 'str'>
a = lambda ignore_this, x=2: type(x)
a("Hello")
=> <type 'int'>Code: Select all
def cb(channel):
etc.I get this error:elParaguayo wrote:Does that work?
I thought the add_event_callback passed the channel as the first argument so, if you're using a lambda and don't care about the channel, you'd need to doCompare:Code: Select all
cb = lambda channel, arg1=valueToPass: functionToCall(arg1) GPIO.add_event_callback(channel, cb, bouncetime=200)If, however, you just want the channel then you don't need the lambda. Your callback function would just be:Code: Select all
a = lambda x=2: type(x) a("Hello") => <type 'str'> a = lambda ignore_this, x=2: type(x) a("Hello") => <type 'int'>Code: Select all
def cb(channel): etc.
callback=lambda echoPin, startTime: func(echoPin, startTime)elParaguayo wrote:What does your lambda function look like?
That's not going to work. If you want to pass the echoPin and startTime then I think you'll need to do this:mannok wrote:callback=lambda echoPin, startTime: func(echoPin, startTime)elParaguayo wrote:What does your lambda function look like?
Code: Select all
callback=lambda channel, ep=echoPin, st=startTime: func(sp, st)Code: Select all
callback=lambda echoPin: print("Distance", round((time.time()-startEchoTime)*17150), "cm"))It looks way too complex when compared to the somewhat simpler code at https://www.dropbox.com/s/cir2860vdkipv ... _sensor.pyelParaguayo wrote:Looking at your other post, you have this:That looks ok to me.Code: Select all
callback=lambda echoPin: print("Distance", round((time.time()-startEchoTime)*17150), "cm"))
Can't see the link, but you're right, if the only parameter being passed is echoPin then there's no need for a lambda at all here.DougieLawson wrote:It looks way too complex when compared to the somewhat simpler code at https://www.dropbox.com/s/cir2860vdkipv ... _sensor.pyelParaguayo wrote:Looking at your other post, you have this:That looks ok to me.Code: Select all
callback=lambda echoPin: print("Distance", round((time.time()-startEchoTime)*17150), "cm"))
Code: Select all
callback = lambda channel, bookshelf=bookshelf: handle_book_pull(channel, bookshelf)
GPIO.add_event_detect(BOOK, GPIO.BOTH, callback, bouncetime=200)