SDA
, SCL
pin configuration when creating the M5UnitOLED display(2, 1, 400000);
instance.
#include <M5Unified.h>
#include <M5GFX.h>
#include <M5UnitOLED.h>
M5UnitOLED display(2, 1, 400000); // SDA, SCL, FREQ
M5Canvas canvas(&display);
static constexpr char text[] = "Hello world ! Hello Unit OLED ! ";
static constexpr size_t textlen = sizeof(text) / sizeof(text[0]);
int textpos = 0;
int scrollstep = 2;
void setup(void)
{
M5.begin();
M5.Display.setFont(&fonts::lgfxJapanMinchoP_32);
M5.Display.setTextDatum(middle_center);
M5.Display.drawString("Unit OLED Test", M5.Display.width() / 2, M5.Display.height() / 2);
display.init();
display.setRotation(1);
canvas.setColorDepth(1); // mono color
canvas.setFont(&fonts::lgfxJapanMinchoP_28);
canvas.setTextWrap(false);
canvas.setTextSize(2);
canvas.createSprite(display.width() + 64, 72);
}
void loop(void)
{
int32_t cursor_x = canvas.getCursorX() - scrollstep;
if (cursor_x <= 0) {
textpos = 0;
cursor_x = display.width();
}
canvas.setCursor(cursor_x, 0);
canvas.scroll(-scrollstep, 0);
while (textpos < textlen && cursor_x <= display.width()) {
canvas.print(text[textpos++]);
cursor_x = canvas.getCursorX();
}
display.waitDisplay();
canvas.pushSprite(&display, 0, (display.height() - canvas.height()) >> 1);
}
For CoreS3, press and hold the reset button (for about 2 seconds) until the internal green LED lights up, and then release it. This indicates the device is in download mode and ready for programming.
Use the CoreS3's PORT.A to control the Unit OLED and display scrolling text.