Skip to content

Instantly share code, notes, and snippets.

@ErgEnn
Created October 13, 2023 12:39
Show Gist options
  • Save ErgEnn/3783359bb2220254258ae83e08cbd318 to your computer and use it in GitHub Desktop.
Save ErgEnn/3783359bb2220254258ae83e08cbd318 to your computer and use it in GitHub Desktop.
MCP23008 test code
#include <Adafruit_MCP23X08.h>
Adafruit_MCP23X08 mcp;
Adafruit_MCP23X08 mcp2;
void setup() {
Serial.begin(115200);
mcp.begin_I2C(0x20);
mcp2.begin_I2C(0x24);
mcp.pinMode(0, INPUT);
mcp.pinMode(1, INPUT);
mcp.pinMode(2, INPUT);
mcp.pinMode(3, INPUT);
mcp.pinMode(4, INPUT);
mcp.pinMode(5, INPUT);
mcp.pinMode(6, INPUT);
mcp.pinMode(7, INPUT);
for(uint8_t address = 0; address < 8; address++){
mcp2.pinMode(address, INPUT);
}
}
void loop() {
for(int address = 0; address < 8; address++){
Serial.print((mcp.digitalRead(address)==HIGH?1:0));
Serial.print(" ");
}for(int address = 0; address < 7; address++){
Serial.print((mcp2.digitalRead(address)==HIGH?1:0));
Serial.print(" ");
}
Serial.println((mcp2.digitalRead(7)==HIGH?1:0));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment