Skip to Content
Learn Robotics Programming
book

Learn Robotics Programming

by Danny Staple
November 2018
Beginner
472 pages
13h 5m
English
Packt Publishing
Content preview from Learn Robotics Programming

Extracting the class

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learn Robotics Programming - Second Edition

Learn Robotics Programming - Second Edition

Danny Staple

Publisher Resources

ISBN: 9781789340747Supplemental Content