May 2019
Intermediate to advanced
542 pages
13h 37m
English
Now that our circuit is connected, we need to write some code to control it. To do this, we're going to make use of the GPIO library on the Pi. Create a copy of your PyQt application template from Chapter 4, Building Applications with QMainWindow, and call it three_color_led_gui.py.
We'll start by importing the GPIO library:
from RPi import GPIO
What we want to do first is to create a Python class that will serve as an API for our circuit. We'll call it ThreeColorLed, and then start it as follows:
class ThreeColorLed(): """Represents a three color LED circuit""" def __init__(self, red, green, blue, pinmode=GPIO.BOARD, freq=50): GPIO.setmode(pinmode)
Our __init__() method takes five arguments: the first three arguments ...
Read now
Unlock full access