#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_MCP23X17.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_MCP23X17 mcp1;
Adafruit_MCP23X17 mcp2;
Adafruit_MCP23X17 mcp3;
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
const int numButtons = 64; // Number of buttons
const int buttonPins[numButtons] = {
22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
}; // Pins for buttons
void setup() {
Wire.begin();
// Initialize MCP23017 modules
mcp1.begin_I2C(0x20); // Address 0
mcp2.begin_I2C(0x21); // Address 1
mcp3.begin_I2C(0x22); // Address 2
// Configure pins as INPUT
for (int i = 0; i < numButtons; i++) {
mcp1.pinMode(i, INPUT);
mcp2.pinMode(i, INPUT);
mcp3.pinMode(i, INPUT);
}
Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
for (int i = 0; i < numButtons; i++) {
pinMode(buttonPins[i], INPUT_PULLUP);
}
}
void loop() {
// Read input states and handle accordingly
// Example: Check if MCP23017-1 pin 33 (GPIO 0) is LOW or HIGH
int state1 = mcp1.digitalRead(0);
if (state1 == LOW) {
// Handle button press on MCP23017-1 pin 33
// ...
}
// Similar handling for other pins on MCP23017-2 and MCP23017-3
display.clearDisplay();
display.setTextSize(6);
display.setTextColor(SSD1306_WHITE);
for (int i = 0; i < numButtons; i++) {
int buttonState = digitalRead(buttonPins[i]);
if (buttonState == LOW) {
display.setCursor(15, 15);
display.print("");// Text before Number
display.print(i + 1);
display.println(""); // Text after Number
}
}
display.display();
delay(100); // Adjust delay as needed
}