Using GPIO for output
Digital output is used to control devices. LEDs are just an easy and visual way to check that things work, and we will start by revisiting them to set the concepts and then look at relays, which are one of the most versatile components we can use.
LEDs
In this section we will see how to handle LEDs directly, learn a bit more about PeripheralManager
(the class you use to access peripherals), and understand how GPIO works for output.
So, let's begin by replacing the utility method from the Rainbow HAT meta driver with some code that accesses the pins directly.
Given that we are already using a Gpio
object to handle the LEDs, the only part that we need to change is how to open it. We already looked atopenLedRed()
from RainbowHat
:
public static Gpio openLedRed() throws IOException { return openLed(BOARD.getLedR()); }
We also looked at BOARD.getLedR()
and how it gives us the pin name which is connected to the Rainbow HAT red LED according to the board. The other part is a generic...