void loop() {
//There are two ways to read from a port, either by returning the full register value as a uin
t8_t, or passing in an array of 8 boolean's to be modified by the function with the statuses of
each pin
uint8_t portValue = myGPIO.digitalReadPort(gpioStatus);
Serial.print("uint8_t: ");
Serial.println(portValue, BIN);
Serial.print("Bool array: ");
for (uint8_t arrayPosition = 0; arrayPosition < NUM_GPIO; arrayP+) {
Serial.print(arrayPosition);
Serial.print(": ");
switch (gpioStatus[arrayPosition])
{
case true:
Serial.print("HIGH");
break;
case false:
Serial.print("LOW");
break;
}
}
Serial.println("\n");
delay(100);
}
Example 3A: Inversion
Example 3A shows how to invert the signal polarity of an input on the Qwiic GPIO. Polarity inversion only works on
pins configured as an input so first we set the pin mode and then we invert the polarity. Input pins default to active
HIGH so inverting it changes it to active LOW. Below you can see the setup required for pin inversion:
myGPIO.pinMode(0, GPIO_IN);
myGPIO.invertPin(0, INVERT);
Once we have set up the pin as an input and inverted the polarity the main loop reads the status of the pin every
100ms:
void loop() {
bool status = myGPIO.digitalRead(0);
switch (status)
{
case true:
Serial.println("GPIO 0: HI");
break;
case false:
Serial.println("GPIO 0: LO");
break;
}
delay(100);
}