#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
int potPin = 34; // Pin analógico donde está conectado el potenciómetro en la ESP32
int motorPin = 12; // 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
// 'logo-espol', 64x64px
const unsigned char epd_bitmap_logo_espol [] PROGMEM = {
// 'logo_espol', 64x64px
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60,
0x0f, 0x00, 0x3c, 0x00, 0xf0, 0x01, 0xe0, 0x60, 0x3f, 0xc0, 0xff, 0x01, 0xfc, 0x07, 0xf0, 0x60,
0x79, 0xe1, 0xe7, 0x83, 0x9e, 0x0e, 0x38, 0x60, 0x60, 0xe3, 0x81, 0x87, 0x07, 0x1c, 0x1c, 0x60,
0xe1, 0xc7, 0x01, 0xc6, 0x03, 0x18, 0x0c, 0x60, 0xff, 0x8e, 0x00, 0xce, 0x03, 0x18, 0x0c, 0x60,
0xff, 0x1c, 0x00, 0xce, 0x03, 0x18, 0x0c, 0x60, 0xe0, 0x38, 0x01, 0xce, 0x03, 0x18, 0x0c, 0x70,
0xe0, 0x70, 0x01, 0x8f, 0x07, 0x1c, 0x1c, 0x30, 0x79, 0xe0, 0x07, 0x8f, 0x9e, 0x0f, 0x38, 0x3c,
0x3f, 0xc0, 0x1f, 0x0f, 0xfc, 0x07, 0xf0, 0x1f, 0x0f, 0x00, 0x1c, 0x0e, 0xf0, 0x01, 0xc0, 0x07,
0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// Array de todos los bitmaps para conveniencia.
const int epd_bitmap_allArray_LEN = 1;
const unsigned char* epd_bitmap_allArray[1] = {
epd_bitmap_logo_espol
};
void showWelcomeMessage() {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.println("Bienvenidos a");
display.println("Sistemas de Control");
display.println("Embebidos");
display.display();
// Esperar unos segundos antes de continuar mostrando la velocidad
delay(2000);
}
void setup(){
Serial.begin(9600);
pinMode(motorPin, OUTPUT);
// Inicializar el display proporcionando el tipo de display y su dirección I2C.
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 está fallando"));
for (;;); // No proceder, hacer un bucle infinito
}
delay(2000); // Pausa de 2 segundos
// Mostrar la imagen al inicio
int xOffset = (DIS_WIDTH - IMG_WIDTH) / 2;
int yOffset = (DIS_HEIGHT - IMG_HEIGHT) / 2 + 10; // Mueve la imagen 10 píxeles hacia abajo
display.clearDisplay();
display.drawBitmap(xOffset, yOffset, epd_bitmap_allArray[0], IMG_WIDTH, IMG_HEIGHT, WHITE);
display.display();
delay(2000); // Pausa de 2 segundos antes de mostrar el mensaje de bienvenida
// Mostrar el mensaje de bienvenida
showWelcomeMessage();
}
void loop()
{
// Continuar mostrando la velocidad en la pantalla
potValue = analogRead(potPin); // Leer el valor del potenciómetro (0 - 4095 en ESP32)
motorSpeed = map(potValue, 0, 4095, 0, 100); // Mapear el valor a un rango de 0 - 255 (para el control PWM)
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.println("Velocidad:");
display.println(motorSpeed);
display.display();
delay(100); // Esperar un breve período antes de actualizar la velocidad nuevamente
analogWrite(motorPin, motorSpeed);
}