May 2019
Intermediate to advanced
542 pages
13h 37m
English
The last method we need to add to our class is a clean-up method. The GPIO pins on the Raspberry Pi can be thought of as a state machine, in which each pin has a state of high or a state of low (that is, on or off). When we set these pins in our program, the state of those pins will remain set after our program exits.
Note that this could cause a problem if we're connecting a different circuit to our Pi; having a pin set to HIGH at the wrong moment while connecting a circuit could fry some of our components. For that reason, we want to leave everything off when we exit the program.
This can be done using the GPIO.cleanup() function:
def cleanup(self): GPIO.cleanup()
By adding this method to our LED driver class, we can easily ...
Read now
Unlock full access