#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
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
const int pot = 34;
void setup() {
Serial.begin(115200);
delay(1000);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
delay(1000);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
}
void loop() {
int potValue = analogRead(pot); // Leer valor del potenciómetro
float voltage = potValue * (3.3 / 4095.0); // Convertir a voltaje
int degrees = map(potValue, 0, 4095, 0, 360); // Mapear a grados (0-360)
// Mostrar en pantalla OLED
display.clearDisplay();
display.setCursor(0, 30);
display.print("Grados: ");
display.print(degrees);
display.display();
// También podemos imprimir en el monitor serial
Serial.print("Potentiometer value: ");
Serial.print(potValue);
Serial.print(" Voltage: ");
Serial.print(voltage);
Serial.print(" Degrees: ");
Serial.println(degrees);
delay(500); // Retardo para lectura cada medio segundo
}