Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import RPi.GPIO as gpio
- class WheelEncoder:
- 'Encapsulates the attributes and methods to use a wheel encoder sensor'
- inputPin = 0
- ticks = 0
- def __init__(self, inputPin):
- self.inputPin = inputPin
- gpio.setmode(gpio.BOARD)
- gpio.setup(self.inputPin, gpio.IN, pull_up_down=gpio.PUD_UP)
- gpio.add_event_detect(self.inputPin, gpio.RISING, event_callback)
- def getTicks(self):
- return self.ticks
- def resetTicks(self):
- self.ticks = 0
- def event_callback(channel):
- self.ticks += 1
- Traceback (most recent call last):
- File "test-WheelEncoder.py", line 5, in <module>
- sensor = WheelEncoder(3, 10, 3)
- File "/home/pi/codes/sensors/WheelEncoder.py", line 20, in __init__
- gpio.add_event_detect(self.inputPin, gpio.RISING, event_callback)
- NameError: global name 'event_callback' is not defined
- gpio.add_event_detect(self.inputPin, gpio.RISING, self.event_callback)
- event_callback(self, channel):
Add Comment
Please, Sign In to add comment