Guest User

Untitled

a guest
Dec 17th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. import RPi.GPIO as gpio
  2.  
  3. class WheelEncoder:
  4. 'Encapsulates the attributes and methods to use a wheel encoder sensor'
  5.  
  6. inputPin = 0
  7. ticks = 0
  8.  
  9. def __init__(self, inputPin):
  10. self.inputPin = inputPin
  11.  
  12. gpio.setmode(gpio.BOARD)
  13. gpio.setup(self.inputPin, gpio.IN, pull_up_down=gpio.PUD_UP)
  14. gpio.add_event_detect(self.inputPin, gpio.RISING, event_callback)
  15.  
  16. def getTicks(self):
  17. return self.ticks
  18.  
  19. def resetTicks(self):
  20. self.ticks = 0
  21.  
  22. def event_callback(channel):
  23. self.ticks += 1
  24.  
  25. Traceback (most recent call last):
  26. File "test-WheelEncoder.py", line 5, in <module>
  27. sensor = WheelEncoder(3, 10, 3)
  28. File "/home/pi/codes/sensors/WheelEncoder.py", line 20, in __init__
  29. gpio.add_event_detect(self.inputPin, gpio.RISING, event_callback)
  30. NameError: global name 'event_callback' is not defined
  31.  
  32. gpio.add_event_detect(self.inputPin, gpio.RISING, self.event_callback)
  33.  
  34. event_callback(self, channel):
Add Comment
Please, Sign In to add comment