Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modified RotaryEncoder MicroPython driver #3

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

zerovijay
Copy link

written in pep 8 style and added error handling for if any one of a pin not provide. and class functions switch_detect,
call_handlers and rotary_change now private also unwanted sum variable the variable only for class. now that variables
are private. also the class __init__ have a object holder we can pass the Pin class directly on the holders like

encoder = RotaryEncoder(
   dt_pin=Pin(0, Pin.IN, Pin.PULL_UP),
   clk_pin=Pin(0, Pin.IN, Pin.PULL_UP),
   sw_pin=Pin(0, Pin.IN, Pin.PULL_UP),
)

or

# Define pins for the rotary encoder
dt_pin = Pin(0, Pin.IN, Pin.PULL_UP)
clk_pin = Pin(1, Pin.IN, Pin.PULL_UP)
sw_pin = Pin(2, Pin.IN, Pin.PULL_UP)

# Create a RotaryEncoder object
encoder = RotaryEncoder(dt_pin, clk_pin, sw_pin)

both are valid. This allow us to pull_down or pull_up the GPIO internal resister. this simple efficient.
not fancy way.
But i notes something on the class if any one of a state like CW or CCW run fast enaph the program face scheduling
error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant