#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for SSD1306 display connected using I2C
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void setup()
{
Serial.begin(9600);
// initialize the OLED object
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,28);
display.print("Voltmeter digital");
display.display();
delay(3000);
display.clearDisplay();
}
void loop() {
int x = analogRead(A0);
float y = x/1023.0 * 5.0;
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,28);
display.print("Voltage : ");
display.print(y);
display.println(" volt");
display.display();
display.clearDisplay();
}