void loop() {
bool gpioState = myGPIO.digitalRead(0);
switch (gpioState) {
case true:
Serial.println("HIGH");
break;
case false:
Serial.println("LOW");
break;
}
delay(250);
}
The example circuit pictured above demonstrates how to monitor an active HIGH input on the Qwiic GPIO by
driving the selected I/O pin (in this case GPIO 0) LOW whenever the button is pressed.
Note:
Defining a pin as an input is not absolutely necessary since GPIO pins on the TCA9534 default to
inputs on power on. We include that call in any example using inputs in case an I/O pin used in the example
was set as an output without power-cycling the Qwiic GPIO.
Example 2B: Read GPIO - Port
Example 2B demonstrates how to read the entire GPIO port on the TCA9534. The code sets up all eight GPIO
pins just like Example 1B using a boolean but this time all pins are set as inputs. We also need to set up a second
boolean for the GPIO pin status due to how the port read register of the TCA9534 works:
bool gpioStatus[NUM_GPIO]
With the port set up and configured, we can move on to initializing the Qwiic GPIO on the I C bus and start
reading the status of the entire GPIO port. As the comment in the code below explains, in order to read from the
port you can either return the full register value as an unsigned 8-bit integer or by passing an array of 8 booleans
modified by the function that returns the status of each pin. The example defaults to the latter and sets up an array
for the port read:
2