Skip to content

Instantly share code, notes, and snippets.

@3110
Last active December 10, 2022 18:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save 3110/aab5376aa27257903b4b3b9bc71b86d4 to your computer and use it in GitHub Desktop.
Save 3110/aab5376aa27257903b4b3b9bc71b86d4 to your computer and use it in GitHub Desktop.
ATOM Lite/MatrixをBLEキーボードにして,特定の文字列を送付する。
/*
* ATOM Lite/MatrixをBLEキーボードにして,特定の文字列を送付する。
*
* 例えば,決まったWi-FiのSSIDに対するパスワードを送るといった用途に使えます。
*
*/
#include <BleKeyboard.h> // https://github.com/T-vK/ESP32-BLE-Keyboard
#include <M5Atom.h>
const std::string SEND_STRING("Hello World!"); // 送りたい文字列
const std::string DEVICE_NAME("ATOM Send String");
const std::string DEVICE_MANUFACTURER("M5Stack");
const CRGB CRGB_BLE_CONNECTED(0x00, 0x00, 0xf0);
const CRGB CRGB_BLE_DISCONNECTED(0xf0, 0x00, 0x00);
const bool ENABLE_SERIAL = true;
const bool ENABLE_I2C = false;
const bool ENABLE_DISPLAY = true;
BleKeyboard bleKeyboard(DEVICE_NAME, DEVICE_MANUFACTURER);
bool isBleConnected = false;
void setup() {
bleKeyboard.begin();
M5.begin(ENABLE_SERIAL, ENABLE_I2C, ENABLE_DISPLAY);
M5.dis.fillpix(CRGB_BLE_DISCONNECTED);
}
void loop() {
M5.update();
if (bleKeyboard.isConnected()) {
if (!isBleConnected) {
M5.dis.fillpix(CRGB_BLE_CONNECTED);
isBleConnected = true;
Serial.println("Connected");
}
if (M5.Btn.wasPressed()) {
bleKeyboard.write((uint8_t *)SEND_STRING.c_str(),
SEND_STRING.length());
Serial.print("Send String: ");
Serial.println(SEND_STRING.c_str());
}
} else {
if (isBleConnected) {
M5.dis.fillpix(CRGB_BLE_DISCONNECTED);
isBleConnected = false;
Serial.println("Disconnected");
}
}
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment