I have several lever switches that represent scores. I want a single callback function when pressed that acts on the value of that lever. I have this working except it seems to call the function twice. This stops happening if I remove the second add_event_detect for the other channel
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(27, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
def buttonPressed(value):
print('Scored! %s'%value)
print(time.time())
GPIO.add_event_detect(17, GPIO.FALLING, callback=lambda x: buttonPressed(50), bouncetime=2000)
GPIO.add_event_detect(27, GPIO.FALLING, callback=lambda x: buttonPressed(150), bouncetime=2000)
When I push the switch once on channel 17 I get outputted:
Scored! 50
1374739135.76
Scored! 50
1374739135.76
Note the extra space on the third line, not sure if that has any importance to the issue.
How can I make sure it only gets called once when the lever is pressed and why is adding the second add_event_detect causing the callback function to be fired?