November 2018
Beginner
472 pages
13h 5m
English
We'd already made a class, so this can be moved to the encoder_counter.py (https://github.com/PacktPublishing/Learn-Robotics-Fundamentals-of-Robotics-Programming/blob/master/chapter12/encoder_counter.py) file. This needs the import for the DigitalInputDevice and has the same constructor, which is also the case when changed. The direction member has been added to account for reversing:
from gpiozero import DigitalInputDeviceclass EncoderCounter(object): def __init__(self, pin_number): self.device = DigitalInputDevice(pin=pin_number) self.device.pin.when_changed = self.when_changed self.pulse_count = 0 self.direction = 1...
Our when_changed handler should use the direction, and we need a method to set this direction. We ...