#include <SPI.h>
#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);
const int potPin = A1;
const int signalPin = A0;
void setup() {
// Initialize the OLED display
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
display.clearDisplay();
// Set up the analog pins
pinMode(potPin, INPUT);
pinMode(signalPin, INPUT);
}
void loop() {
// Read the potentiometer value to determine time base
int timeBase = map(analogRead(potPin), 0, 1023, 1, 1000); // Adjust range as needed
// Variables to store max voltage and current voltage
int maxVoltage = 0;
// Clear the display
display.clearDisplay();
// Plot the signal on the display
for(int x = 0; x < SCREEN_WIDTH; x++) {
// Read the input signal value
int signalValue = analogRead(signalPin);
// Map signal value to display height
int y = map(signalValue, 0, 1023, SCREEN_HEIGHT, 0);
// Draw point on display
display.drawPixel(x, y, WHITE);
// Update max voltage if current voltage is greater
if (signalValue > maxVoltage) {
maxVoltage = signalValue;
}
// Increment x according to time base
delayMicroseconds(timeBase);
}
// Display max voltage
display.setTextSize(1);
display.setCursor(0, 0);
display.setTextColor(WHITE);
display.print("maxVoltage: ");
display.print(map(maxVoltage, 0, 1023, 0, 5)); // Map analog reading to voltage range
display.print(" V");
display.display();
}