One of the great advantages of working with Python as our programming language to interact with the board is that we have plenty of packages available for Python. We have been using the mraa
library to interact with the digital outputs. However, in the previous chapter, we also installed the wiring-x86
library. We can change just a few lines of our object-oriented code to replace the mraa
library with the wiring-x86
one to turn on and off the LEDs.
The following lines shows the code for a Board
class followed by the new version of the Led
class that works with the wiring-x86
library instead of using mraa
. The code file for the sample is iot_python_chapter_03_07.py
.
from wiringx86 import GPIOGalileoGen2 as GPIO import time class Board: gpio = GPIO(debug=False) class Led: def __init__(self, pin, position): self.pin = pin self.position = position self.gpio = Board.gpio self.gpio.pinMode(pin, self...