Given that the intention of GpioZero is to make components as easy to use as possible, and all the Button examples in the docs just do e.g. button = Button(2) I wonder if it might make sense for bounce_time in the Button init-method to default to something other than None ?
I suspect that up until now this hasn't really been an issue since most of the examples just use a Button to turn on and off an LED, in which case you won't notice the switch-bounce. But if you do something like printing a string to the screen when the button was pressed or released, a 'noisy' switch will trigger multiple press or release events for each real press or release.
And something I just remembered while reading some old blog-comments is that IIRC the way the bounce_time works in RPi.GPIO is that if you have a bounce-time of e.g. 100 milliseconds, and then register a falling-edge callback, pressing the button will trigger the callback as expected. But if you then hold the button down for a second (so that the bounce-time has elapsed) and then release the button, the switch-bounce on the release event can cause an additional falling-edge callback to be triggered. If this is still the case (I can't be sure, I'll have to check later) it would be great to see this handled 'properly' inside GpioZero so that only real button-presses trigger the button_pressed callback, no matter how long the switch is held down for before releasing it.
Given that the intention of GpioZero is to make components as easy to use as possible, and all the Button examples in the docs just do e.g.
button = Button(2)I wonder if it might make sense forbounce_timein the Button init-method to default to something other thanNone?I suspect that up until now this hasn't really been an issue since most of the examples just use a Button to turn on and off an LED, in which case you won't notice the switch-bounce. But if you do something like printing a string to the screen when the button was pressed or released, a 'noisy' switch will trigger multiple press or release events for each real press or release.
And something I just remembered while reading some old blog-comments is that IIRC the way the
bounce_timeworks in RPi.GPIO is that if you have a bounce-time of e.g. 100 milliseconds, and then register a falling-edge callback, pressing the button will trigger the callback as expected. But if you then hold the button down for a second (so that the bounce-time has elapsed) and then release the button, the switch-bounce on the release event can cause an additional falling-edge callback to be triggered. If this is still the case (I can't be sure, I'll have to check later) it would be great to see this handled 'properly' inside GpioZero so that only real button-presses trigger the button_pressed callback, no matter how long the switch is held down for before releasing it.