#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
int potPin = A0; // Pin analógico donde está conectado el potenciómetro
int motorPin = 9; // Pin de control del motor (por ejemplo, si estás usando un L298N)
int potValue;
int motorSpeed;
Adafruit_SSD1306 display(-1);
#define DIS_WIDTH 128 // OLED display width, in pixels
#define DIS_HEIGHT 64 // OLED display height, in pixels
#define IMG_HEIGHT 128
#define IMG_WIDTH 64
void setup(){
Serial.begin(9600);
pinMode(motorPin, OUTPUT);
//Initialize display by providing the display type and its I2C address.
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 está fallando"));
for (;;); // Don't proceed, loop forever
}
delay(2000); // Pause for 2 seconds
display.clearDisplay();
}
void loop()
{
potValue = analogRead(potPin); // Leer el valor del potenciómetro (0 - 1023)
motorSpeed = map(potValue, 0, 1023, 0, 100); // Mapear el valor a un rango de 0 - 255 (para el control PWM)
analogWrite(motorPin, motorSpeed);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.println("Velocidad:");
display.println(motorSpeed);
display.display();
}