#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 counter, buttonPin = 2, torque[128]; // <-- store 128 values
bool oldButtonState;

void setup() {
  Serial.begin(115200);
  pinMode(buttonPin, INPUT_PULLUP);
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 failed"));
    while (1);
  }
  display.clearDisplay();
}

void loop() {
  display.drawLine(counter, 0, counter, 63, BLACK); // verticle line to erase trace
  display.display();
  readButton();
  writeBuffer();
}

void readButton() {
  if (digitalRead(buttonPin)) {
    torque[counter] = SCREEN_MIDDLE - 10;
    display.drawPixel(counter, SCREEN_MIDDLE - 10, WHITE);
  } else {
    torque[counter] = SCREEN_MIDDLE + 10;
    display.drawPixel(counter, SCREEN_MIDDLE + 10, WHITE);
  }
  display.display();
}

void writeBuffer() {
  counter++; // next pixel
  if (counter == 128) { // OLED right edge
    for (int j = 0; j < SCREEN_WIDTH / 16; j++) { // 8 rows
      for (int i = 0; i < SCREEN_WIDTH / 8; i++) { // 16 columns
        if ((torque[j * 8 + i]) < 100) Serial.print(" "); // pad tens
        if ((torque[j * 8 + i]) < 10)  Serial.print(" "); // pad ones
        Serial.print(torque[j * 8 + i]); // data block
        Serial.print(" "); // spacing
      }
      Serial.println(); // next line
      counter = 0; // reset column counter
    }
    Serial.println(); // separate blocks
  }
}