#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
const int switchPins[] = {2, 3, 4, 5};
const int buttonPins[] = {6, 7, 8, 9};
void setup() {
Serial.begin(9600);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
delay(2000);
display.clearDisplay();
display.display();
}
void loop() {
// Read state of switches
int switchStates[4];
for (int i = 0; i < 4; ++i) {
switchStates[i] = digitalRead(switchPins[i]);
}
// Read state of push buttons
int buttonStates[4];
for (int i = 0; i < 4; ++i) {
buttonStates[i] = digitalRead(buttonPins[i]);
}
// Display the state on OLED
display.clearDisplay();
display.setTextSize(2.5);
display.setTextColor(SSD1306_WHITE);
display.setCursor(3, 10);
display.print("I- ");
for (int i = 0; i < 4; ++i) {
display.print(switchStates[i]);
display.print(" ");
}
display.setCursor(3, 35); // Move to the next line
display.print("O- ");
for (int i = 0; i < 4; ++i) {
display.print(buttonStates[i]);
display.print(" ");
}
display.display();
delay(1000);
}