実際のところ
#include <Arduino.h>
#include <M5Core2.h>
#include <BleGamepad.h>
BleGamepad bleGamepad;
int circleX = 160;
int circleY = 120;
int circleRadius = 20;
uint32_t circleColor = WHITE;
void setup() {
M5.begin();
Serial.begin(115200);
Serial.println("Starting BLE work!");
bleGamepad.begin();
M5.Lcd.fillScreen(BLACK);
M5.Lcd.fillCircle(circleX, circleY, circleRadius, circleColor);
}
void loop() {
if (bleGamepad.isConnected()) {
if (bleGamepad.isPressed(BUTTON_5)) {
circleColor = RED;
}
else if (bleGamepad.isPressed(BUTTON_16)) {
circleColor = BLUE;
}
else {
circleColor = WHITE;
}
if (bleGamepad.getHat1() == HAT_UP) {
circleY = max(circleY - 1, circleRadius);
}
else if (bleGamepad.getHat1() == HAT_DOWN) {
circleY = min(circleY + 1, 240 - circleRadius);
}
if (bleGamepad.getHat1() == HAT_LEFT) {
circleX = max(circleX - 1, circleRadius);
}
else if (bleGamepad.getHat1() == HAT_RIGHT) {
circleX = min(circleX + 1, 320 - circleRadius);
}
M5.Lcd.fillScreen(BLACK);
M5.Lcd.fillCircle(circleX, circleY, circleRadius, circleColor);
}
delay(100);
}
参考もと