Last active
January 28, 2025 11:43
-
-
Save ksasao/7bbaf3339d51db777e4573439f173ae5 to your computer and use it in GitHub Desktop.
M5Cardputerで日本語表示。このコードには漢字変換機能はありません。https://x.com/ksasao/status/1884198721749213610
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
/** | |
* @file inputText.ino | |
* @author SeanKwok ([email protected]) | |
* @brief M5Cardputer input text test | |
* @version 0.1 | |
* @date 2023-10-13 | |
* | |
* | |
* @Hardwares: M5Cardputer | |
* @Platform Version: Arduino M5Stack Board Manager v2.0.7 | |
* @Dependent Library: | |
* M5GFX: https://github.com/m5stack/M5GFX | |
* M5Unified: https://github.com/m5stack/M5Unified | |
*/ | |
#include "M5Cardputer.h" | |
#include "M5GFX.h" | |
M5Canvas canvas(&M5Cardputer.Display); | |
String data = "> "; | |
void setup() { | |
auto cfg = M5.config(); | |
M5Cardputer.begin(cfg, true); | |
M5Cardputer.Display.setRotation(1); | |
M5Cardputer.Display.setTextSize(1); | |
M5Cardputer.Display.drawRect(0, 0, M5Cardputer.Display.width(), | |
M5Cardputer.Display.height() - 28, GREEN); | |
M5Cardputer.Display.setTextFont(&fonts::efontJA_16); | |
M5Cardputer.Display.fillRect(0, M5Cardputer.Display.height() - 4, | |
M5Cardputer.Display.width(), 4, GREEN); | |
canvas.setTextFont(&fonts::efontJA_16); | |
canvas.setTextSize(1); | |
canvas.createSprite(M5Cardputer.Display.width() - 8, | |
M5Cardputer.Display.height() - 36); | |
canvas.setTextScroll(true); | |
canvas.println("テキストを入力するにはEnterを押してください"); | |
canvas.pushSprite(4, 4); | |
M5Cardputer.Display.drawString(data, 4, M5Cardputer.Display.height() - 24); | |
} | |
void loop() { | |
M5Cardputer.update(); | |
if (M5Cardputer.Keyboard.isChange()) { | |
if (M5Cardputer.Keyboard.isPressed()) { | |
Keyboard_Class::KeysState status = M5Cardputer.Keyboard.keysState(); | |
for (auto i : status.word) { | |
data += i; | |
} | |
if (status.del) { | |
data.remove(data.length() - 1); | |
} | |
if (status.enter) { | |
data.remove(0, 2); | |
canvas.println(data); | |
canvas.pushSprite(4, 4); | |
data = "> "; | |
} | |
M5Cardputer.Display.fillRect(0, M5Cardputer.Display.height() - 28, | |
M5Cardputer.Display.width(), 25, | |
BLACK); | |
M5Cardputer.Display.drawString(data, 4, | |
M5Cardputer.Display.height() - 24); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment