May 2019
Intermediate to advanced
542 pages
13h 37m
English
Start a new class at the top of your script to be the driver for our push button:
class HWButton(qtc.QObject): button_press = qtc.pyqtSignal()
Once again, we're using QObject so that we can emit Qt signals, which we'll do when we detect that the button has been pushed down.
Now, let's write the constructor, as follows:
def __init__(self, pin): super().__init__() self.pin = pin GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
The first thing our __init__() method does after calling super().__init__() is configure our button's GPIO pin to be an input pin by passing the GPIO.IN constant to the setup() function.
The pull_up_down value we've passed here is very important. Because of the way we've connected this ...
Read now
Unlock full access