// #include <Wire.h>
// #include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define SCREEN_MIDDLE SCREEN_HEIGHT / 2
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
int i, buttonPin = 2;
bool oldButtonState;
void setup() {
pinMode(buttonPin, INPUT_PULLUP);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 failed"));
while (1);
}
display.clearDisplay();
}
void loop() {
display.drawLine(i, 0, i, 63, BLACK); // verticle line to erase trace
display.display();
if (digitalRead(buttonPin)) {
display.drawPixel(i, SCREEN_MIDDLE - 10, WHITE);
} else {
display.drawPixel(i, SCREEN_MIDDLE + 10, WHITE);
}
display.display();
i++; // next pixel
if (i == 128) { // OLED right edge
i = 0; // reset i
}
}