#include <Wire.h> //Libreria para comunicaciones I2C
#include <Adafruit_SSD1306.h>;
#define ANCHO_PANTALLA 128 // en pixeles
#define ALTO_PANTALLA 64 // en pixeles
// crear un objeto de pantalla OLED conectado a I2C
Adafruit_SSD1306 oled(ANCHO_PANTALLA, ALTO_PANTALLA, &Wire, -1);
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
// initialize OLED display with address 0x3C for 128x64
if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { //Se utiliza la direccion 0x3C de I2C
Serial.println(F("Fallo SSD1306"));
while (true);
}
delay(1000); // aguardar 1 segundo para inicializar
}
void loop() {
escribe_pantalla("Hola mundo");
delay(500);
}
void escribe_pantalla(String mensaje) {
oled.clearDisplay(); // limpia pantall
oled.setTextSize(2); // establece el tamaño del texto
oled.setTextColor(WHITE); // Establece el color del texto
oled.setCursor(0, 10); // posiciona el cursor para donde inicia el mensaje
oled.print(mensaje); // envia mensaje
oled.display(); // muestra en pantalla lo almacenado
}