You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Maybe it's because you're pressing the button multiple times when you think you pressed once. You can use Ludovic's Detec_button.py in Magic_Wand it should fix the problem
It is probably because of rebounds (mechanical vibration when opening and closing the switch).
To simplify your code you could use a callback function. That is function called whenever a button is pressed. (see tutorial/buttons.py)
## configure the list of input channels
button_channels = [14, 15, 18]
GPIO.setmode(GPIO.BCM)
def button_callback(channel):
"""Print the channel number to the console."""
print("callback function for button ", channel)
## setup all channels as inputs with a pull-up resistor. When pushing a
## button the state goes from HIGH to LOW (falling edge)
for channel in button_channels:
GPIO.setup(channel, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.add_event_detect(channel, GPIO.FALLING, bouncetime=200)
GPIO.add_event_callback(channel, button_callback)
Sometimes, when the button is pressed, the function onButtonPressed handles more than once.
The text was updated successfully, but these errors were encountered: