Skip to content

Ubuntu DigitalInputDevice .when_activated not firing #1083

Answered by lurch
KevWal asked this question in Q&A
Discussion options

You must be logged in to vote
    def __init__(self, pin):
        self._value = 0
        encoder = DigitalInputDevice(pin, pull_up=True)
        encoder.when_activated = self._increment
        encoder.when_deactivated = self._increment
        print("Init")

In the function above, encoder is a local variable, and so I think it will go out of scope (and get garbage-collected) at the end of the function. Does your code work any better if you do self._encoder = ... instead?

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@KevWal
Comment options

Answer selected by KevWal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1082 on June 26, 2023 18:21.