Function 'button_1' repeating without pressing button - Using Micropython and Pi Pico #11727
Replies: 2 comments 2 replies
-
"(...)But then, repeats without button presses." do you mean you press button and it repeat handler function couple times ? if yes then it is caused by mechanical button contacts vibration : bouncing effect) and a some debouncing must be implemented (software or mechanical), but best way is to use Pushbutton class it is async and already have debouncing and press and release event functions. |
Beta Was this translation helpful? Give feedback.
-
@floordoc I suggest you read this official doc on how to write an interrupt service routine (ISR). Hard interrupts are not the best way to interface mechanical switches and complex ISR's are bad practice. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
This is my first post to the forum. I have found helpful posts here before, but have not found any posts similar to the problem I'm currently having. I've tried to include all of the relevant information including, the hardware being used, as well as the full code we are trying to develop. However, if things are missing, let me know. New to Python coding so the program is certainly not the most efficient.
Within the posted program, 'button_1' does not run until the button is pressed the first time. But then, repeats without button presses.
For the hardware setup we have an IR Reflectivity sensor connected to the Pi Pico at pins (ground@pin 35, 3V3out@pin36, pin35, GP28@pin 34). We have a SPST Normally open momentary push button connected to pins (ground@pin18, gp14@pin19). We have a 16x2 display connected at (Vbus@pin40, gp0@pin1, gp1@pin2, ground@pin3).
We are incrementing a counter 'drop' for each button press. The drop counter goes from 1-4. When drop =4 we are computing 1 of 2 averages. We are also incrementing a 'test' counter. The test increments when the drop=4, at which time drop is returned to 1.
Beta Was this translation helpful? Give feedback.
All reactions