November 2018
Beginner
472 pages
13h 5m
English
To integrate this into our robot, we will start by creating a DistanceSensor object. It will have a simple get_distance method. This is a simple interface which we could swap out for implementations of other distance sensors. We will construct it with the two pin numbers. This code will look quite familiar to the code we tested. Put this into distance_sensor_hcsr04.py.
Start again with some imports, and this time, a docstring for the module. Module docstrings usually state why a module exists or what it is for:
"""Object for the HC-SR04 distance sensor type."""import time # import the whole thing, we need more than just sleepfrom gpiozero import DigitalInputDevice, DigitalOutputDevice...
As we saw in the ...