Skip to content
Snippets Groups Projects
Commit 262de0fd authored by jhierck laptop's avatar jhierck laptop
Browse files

Fixed small issues with encoder.py

parent fd23ab9a
No related branches found
No related tags found
No related merge requests found
......@@ -9,12 +9,12 @@ class Encoder:
def __init__(self, name, encoder_pin: int):
global pulse_count
self.name = name
self.encoder_pin = encoder_pin;
self.encoder_pin = encoder_pin
pulse_count = 0
GPIO.setup(self.encoder_pin, GPIO.IN, GPIO.PUD_DOWN)
def callback_encoder(self):
def callback_encoder(self, channel):
global pulse_count
pulse_count += 1
......@@ -26,12 +26,12 @@ class Encoder:
pulse_count = 0
def init_callback(self):
GPIO.add_event_detect(encoder_pin, GPIO.BOTH, callback = callback_encoder(), bouncetime = 10)
GPIO.add_event_detect(self.encoder_pin, GPIO.BOTH, callback = self.callback_encoder, bouncetime = 10)
try:
encoder1 = Encoder(name="encoder1", encoder_pin=16)
encoder1.init_callback
encoder1 = Encoder(name="encoder1", encoder_pin=4)
encoder1.init_callback()
while True:
print(encoder1.get_pulse_count())
time.sleep(1)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment