Using GPIO for input
Now that we have seen how to use GPIO for output, let's move on to input. In this section we will look at accessing Button
and ButtonDriver
without using the meta driver of the Rainbow HAT. Both drivers are a layer of abstraction over GPIO, so our next step will be to learn how to work with GPIO directly. Finally, we will look at a few sensors that generate a GPIO signal and how to use them.
Buttons
Buttons are quite simple to deal with when using the driver or the input driver, but they can also be used to learn how to use GPIO output at a low level.
Let's get into the button driver.
Button driver
First, we will remove the Rainbow HAT meta driver from dependencies
and add an entry for the button driver instead. This driver includes both the button and the button input drivers.
dependencies { [...] implementation 'com.google.android.things.contrib:driver-button:+' }
In a similar way as we did for LEDs, let's look at the code of the wrapper function:
public static Button...