adafruit / adafruit/Adafruit_CircuitPython_Debouncer

Confusing behavior when long intervals between .`update()`

Open
#44 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
19
Forks
14
PR merge metrics
No merged PRs in 30d

Description

When there is a long interval between .`update()` calls, `.value` is not what is expected.

Originally from https://discord.com/channels/327254708534116352/537365702651150357/1341836635373047941

```py
import board, digitalio, time
from adafruit_debouncer import Button

# Tested on a Circuit Playground Bluefruit, which connects the far side of the buttons to +V.
Adjust pulls and value_when_pressed as needed.

button_A_input = digitalio.DigitalInOut(board.BUTTON_A)
button_A_input.switch_to_input(digitalio.Pull.DOWN)
button_A = Button(button_A_input, value_when_pressed = True)
button_B_input = digitalio.DigitalInOut(board.BUTTON_B)
button_B_input.switch_to_input(digitalio.Pull.DOWN)
button_B = Button(button_B_input, value_when_pressed = True)

def step(t, msg):
button_A.update()
button_B.update()
print(f"time: {t}, button_A: {button_A.pressed}, button_B: {button_B.pressed}")
print(msg)
time.sleep(5)
return t + 5

t = 0
t = step(t, "start with no buttons pressed")
t = step(t, "continue with no buttons pressed")
t = step(t, "press and hold A")
t = step(t, "continue holding A")
t = step(t, "press and hold B, in addition")
t = step(t, "continue holding A and B")
t = step(t, "continue holding A and B")
t = step(t, "release A")
t = step(t, "release B")
t = step(t, "continue with both released")
```
Follow the directions as printed when testing.
```
time: 0, button_A: False, button_B: False
start with no buttons pressed
time: 5, button_A: False, button_B: False
continue with no buttons pressed
time: 10, button_A: False, button_B: False
press and hold A
time: 15, button_A: False, button_B: False
continue holding A
time: 20, button_A: True, button_B: False
press and hold B, in addition
time: 25, button_A: False, button_B: False
continue holding A and B
time: 30, button_A: False, button_B: True
continue holding A and B
time: 35, button_A: False, button_B: False
release A
time: 40, button_A: False, button_B: False
release B
time: 45, button_A: False, button_B: False
continue with both released
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the provided CircuitPython example with Button.update() and inspect the Button implementation, focusing on how .pressed is computed after each five-second sleep. Compare each printed state with the physical actions and establish the intended behavior for long gaps before adding a regression test and confirming the corrected sequence.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
embedded-iot
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.