Created
February 4, 2024 08:51
-
-
Save haratta27/15601966a118f31d68e251c6e2c6d1ee to your computer and use it in GitHub Desktop.
M5stack Core2 と Glass2 Unit 両方の画面表示をする サンプルコード
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
#include <Arduino.h> | |
#include <M5Unified.h> | |
#include <M5UnitGLASS2.h> | |
M5UnitGLASS2 display; // default setting //auto | |
//M5UnitGLASS2 display( 32, 33, 400000 ); // SDA, SCL, FREQ | |
M5Canvas canvas(&display); | |
static constexpr char text[] = "Hello world ! こんにちは世界! this is long long string sample. 寿限無、寿限無、五劫の擦り切れ、海砂利水魚の、水行末・雲来末・風来末、喰う寝る処に住む処、藪ら柑子の藪柑子、パイポ・パイポ・パイポのシューリンガン、シューリンガンのグーリンダイ、グーリンダイのポンポコピーのポンポコナの、長久命の長助"; | |
static constexpr size_t textlen = sizeof(text) / sizeof(text[0]); | |
int textpos = 0; | |
int scrollstep = 2; | |
void setup(void) | |
{ | |
auto cfg = M5.config(); | |
M5.begin(cfg); // Init M5Core2. | |
M5.Lcd.fillScreen(WHITE); // Set the screen background. | |
delay(500); // Delay 500ms. | |
M5.Lcd.fillScreen(RED); | |
delay(500); | |
M5.Lcd.fillScreen(GREEN); | |
delay(500); | |
M5.Lcd.fillScreen(BLUE); | |
delay(500); | |
M5.Lcd.fillScreen(BLACK); | |
delay(500); | |
M5.Lcd.setCursor(10, 10); // Move the cursor position to (x,y). | |
M5.Lcd.setTextColor(WHITE); // Set the font color to white. | |
M5.Lcd.setTextSize(3); // Set the font size. | |
M5.Lcd.printf("Display Test!"); // Serial output format string. | |
// draw graphic | |
delay(1000); | |
display.begin(); | |
display.setColorDepth(2); | |
if (display.isEPD()) | |
{ | |
scrollstep = 16; | |
display.setEpdMode(epd_mode_t::epd_fastest); | |
display.invertDisplay(true); | |
display.clear(TFT_BLACK); | |
} | |
if (display.width() < display.height()) | |
{ | |
display.setRotation(display.getRotation() ^ 1); | |
} | |
canvas.setColorDepth(1); // mono color | |
canvas.setFont(&fonts::lgfxJapanMinchoP_32); | |
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(); | |
int y = (display.height() - canvas.height()) >> 1; | |
canvas.pushSprite(&display, 0, y); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment