Skip to content

Instantly share code, notes, and snippets.

@hirosh
Created December 24, 2023 11:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hirosh/3bed7ccf75627406fc4057b56725ba3b to your computer and use it in GitHub Desktop.
Save hirosh/3bed7ccf75627406fc4057b56725ba3b to your computer and use it in GitHub Desktop.
#include <BleKeyboard.h>
#include <M5Unified.h>
BleKeyboard bleKeyboard;
void setup() {
auto cfg = M5.config();
M5.begin(cfg);
M5.Power.begin();
bleKeyboard.begin();
M5.Display.setBrightness(20);
}
void loop() {
if (bleKeyboard.isConnected()) {
M5.update();
static unsigned long lastTime = 0;
float accX, accY, accZ;
M5.Imu.getAccel(&accX, &accY, &accZ);
if (M5.BtnA.wasPressed()) {
if (accX > 0) {
bleKeyboard.write(KEY_RIGHT_ARROW);
} else if (accX < 0) {
bleKeyboard.write(KEY_LEFT_ARROW);
}
}
} else {
M5.Display.println("Waiting for connection...");
delay(2000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment