Skip to content

Instantly share code, notes, and snippets.

@wesleyit
Created November 10, 2023 22:15
Show Gist options
  • Select an option

  • Save wesleyit/90356160fc4dd6c18974076b55d42c80 to your computer and use it in GitHub Desktop.

Select an option

Save wesleyit/90356160fc4dd6c18974076b55d42c80 to your computer and use it in GitHub Desktop.

Revisions

  1. wesleyit created this gist Nov 10, 2023.
    50 changes: 50 additions & 0 deletions Node_MCU_OLED_Show_Text.ino
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    #include <Arduino.h>
    #include <U8g2lib.h>
    #include <Wire.h>

    // This line will initialize the OLED display properly
    U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ 12, /* data=*/ 14, /* reset=*/ U8X8_PIN_NONE);

    #define U8LOG_WIDTH 14 // Width of ulog object
    #define U8LOG_HEIGHT 4 // Height of ulog object

    // The size necessary for the ulog buffer
    uint8_t u8log_buffer[U8LOG_WIDTH * U8LOG_HEIGHT];
    U8G2LOG u8g2log;

    void setup(void) {
    // Init the display
    u8g2.begin();

    // Init the ulog object
    u8g2log.begin(U8LOG_WIDTH, U8LOG_HEIGHT, u8log_buffer);
    }

    String nome = String("Em volta do buraco, tudo eh beira.\n--Ariano Suassuna\f");
    int counter = 0;

    void loop(void) {

    // The text from the ulog object need to be printed
    // before the screen is assembled
    u8g2log.print(nome[counter]);

    // Then, create the screen layout calling the ulog object
    u8g2.firstPage();
    do {
    u8g2.setFont(u8g2_font_commodore64_tr); // font for the title
    u8g2.setCursor(0, 14); // title position on the display
    u8g2.print("Sabedoria:"); // output title
    u8g2.setFont(u8g2_font_unifont_tf); // set the font for the terminal window
    u8g2.drawLog(0, 28, u8g2log); // draw the terminal window on the display
    } while (u8g2.nextPage());

    if (counter > nome.length()) {
    counter = 0;
    }
    else {
    counter++;
    }

    delay(50);
    }