domingo, 15 de febrero de 2026

6 FISRT OLED CODE HELLO WORLD

 /*

 * WELCOME TO C++ PROGRAMMING - GRADE 6
 * This is your first program! We will print a name on the OLED screen.
 */

// 1. LIBRARIES ( The Tools )
// We include special "books" of code that teach the ESP32 how to use the screen.
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

// 2. SCREEN CONFIGURATION ( The Hardware )
// We tell the ESP32 the size of our screen (128 pixels wide, 64 pixels tall).
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

// We create a "control object" for the screen. Think of this as the remote control.
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

// 3. YOUR VARIABLES ( The Data )
// **********************************************************
// STUDENT: CHANGE THE TEXT INSIDE THE QUOTES BELOW!
// **********************************************************
String name_here = "MARIE CURIE";

void setup() {
  // This part runs ONLY ONE TIME when you turn on the ESP32.
 
  // A. Start the connection to the screen
  // (0x3C is the address/ID of the screen)
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    // If the screen is not found, stop here.
    for(;;);
  }

  // B. Clean the screen (erase old drawings)
  display.clearDisplay();

  // C. Set up the text style
  display.setTextSize(2);      // Size of the text (1 is small, 2 is medium)
  display.setTextColor(WHITE); // Color of the text (OLEDs are usually only one color)
 
  // D. Choose where to start writing (Column 10, Row 20)
  display.setCursor(10, 20);

  // E. Print the variable we created above
  display.println(name_here);

  // F. IMPORTANT: Push the information to the screen!
  // Nothing appears until we use this command.
  display.display();
}

void loop() {
  // This part repeats forever.
  // Since we only want to show the name once, we leave this empty!
  // Relax, ESP32!
}

No hay comentarios:

Publicar un comentario