Last active
October 7, 2023 09:07
-
-
Save mongonta0716/1b4ffa2ea43671bcae156e3a3f616b0e to your computer and use it in GitHub Desktop.
M5StackにGLASS2 Unitを接続して文字をスクロールするサンプル(OLEDUnitやLCDUnitでもL4, L45を変更すると利用できます。)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// reference | |
// https://github.com/lovyan03/inside_magimajopures/tree/main/640x48_LCD_ESP32_TextScroll | |
#include <M5UnitGLASS2.h> | |
#include <M5Unified.h> | |
M5GFX gfx; | |
M5Canvas canvas; | |
int glass2index = 0; | |
static constexpr char text[] = "M5Stack楽しいよ!"; | |
static constexpr size_t textlen = sizeof(text) / sizeof(text[0]); | |
int textpos = 0; | |
int scrollstep = 2; | |
void glass2Loop(void *args) { | |
for(;;) { | |
int32_t cursor_x = canvas.getCursorX() - scrollstep; | |
if (cursor_x <= 0) | |
{ | |
textpos = 0; | |
cursor_x = gfx.width(); | |
} | |
canvas.setCursor(cursor_x, 0); | |
canvas.scroll(-scrollstep, 0); | |
while (textpos < textlen && cursor_x <= gfx.width()) | |
{ | |
canvas.print(text[textpos++]); | |
cursor_x = canvas.getCursorX(); | |
} | |
M5.getDisplay(glass2index).waitDisplay(); | |
canvas.pushSprite(&gfx, 0, (gfx.height() - canvas.height()) >> 1); | |
vTaskDelay(50/portTICK_PERIOD_MS); | |
} | |
} | |
void setup() { | |
auto cfg = M5.config(); | |
cfg.external_display.unit_glass2 = true; // 外部ディスプレイのGLASS2 UnitをON | |
M5.begin(cfg); | |
M5.Display.setTextSize(2); | |
M5.Display.println("Glass2Unit Test"); | |
glass2index = M5.getDisplayIndex(m5::board_t::board_M5UnitGLASS2); | |
gfx = M5.getDisplay(glass2index); | |
gfx.init(); | |
gfx.setColorDepth(1); | |
canvas.setColorDepth(1); // mono color | |
canvas.setFont(&fonts::lgfxJapanMinchoP_32); | |
canvas.setTextWrap(false); | |
canvas.setTextSize(2); | |
canvas.createSprite(gfx.width() + 64, 72); | |
xTaskCreateUniversal(glass2Loop | |
, "glass2Loop" | |
, 4096 | |
, NULL | |
, 8 | |
, NULL | |
, PRO_CPU_NUM); | |
} | |
void loop() { | |
delay(1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment