#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define ANALOG_PIN A0
#define POT_PIN A1
#define SCALE 4 // 4 default
int readValue = 0;
int potValue = 0;
void setup() {
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.display();
display.setTextSize(1);
display.setTextColor(WHITE);
pinMode(ANALOG_PIN, INPUT);
pinMode(POT_PIN, INPUT);
}
void loop() {
display.clearDisplay();
potValue = analogRead(POT_PIN);
for(int i=0; i<SCREEN_WIDTH; i++) {
delayMicroseconds(potValue);
readValue = analogRead(ANALOG_PIN);
int y = map(readValue, 0, 1023, SCREEN_HEIGHT, 0);
display.drawPixel(i, y / SCALE, WHITE);
}
display.setCursor(0, 0);
display.print("Voltage: ");
display.print(readValue * (5.0 / 1023.0)); // convert to voltage
display.print(" V");
display.display();
}Loading
ssd1306
ssd1306