Python Syntax gpiozero bounce time

With a Pi 5 and using gpiozero the following code works ok with umpteen Hello lines from contact bounce.

from gpiozero import Button
def say_hello():
       print("Hello")
button = Button(6)
button.when_pressed = say_hello

2 questions:

Reading the gpiozero specs I apparently can nominate a bounce time. I cannot work out the syntax for this.

How do you want me to show code in this post?

PS I indented the print(“Hello”) line but the spaces were stripped when I saved it.

2 Likes

The bounce_time is a parameter of the Button constructor, which you can set like this:

myButton = Button(pin=6, bounce_time=0.5)

According to the docs it’s in seconds, so the above example should have a bounce time of half a second.

More details here:
https://gpiozero.readthedocs.io/en/latest/api_input.html#button

1 Like

Here is a link were I go through it :slight_smile:

2 Likes

Both questions neatly answered. Thanks

2 Likes