Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The button detection in LEGO_Bricks/Project.py isn't stable. #5

Open
MrLasagne4 opened this issue Jan 14, 2018 · 3 comments
Open

The button detection in LEGO_Bricks/Project.py isn't stable. #5

MrLasagne4 opened this issue Jan 14, 2018 · 3 comments

Comments

@MrLasagne4
Copy link
Contributor

Sometimes, when the button is pressed, the function onButtonPressed handles more than once.

@AlbertGuedj
Copy link
Contributor

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

@rasql
Copy link
Contributor

rasql commented Jan 14, 2018

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)

@Ludblanc
Copy link
Contributor

Ludblanc commented Jan 16, 2018

Yes my function works well but I am happy to discovered new settings!!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants