Created
December 24, 2023 11:44
-
-
Save hirosh/3bed7ccf75627406fc4057b56725ba3b to your computer and use it in GitHub Desktop.
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 <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