add test code (forgot to push)
This commit is contained in:
73
main.py
Normal file
73
main.py
Normal file
@@ -0,0 +1,73 @@
|
||||
#include <BleGamepad.h>
|
||||
|
||||
BleGamepad bleGamepad("Manette ModulX", "Nono", 100);
|
||||
|
||||
// --------- BOUTONS ---------
|
||||
// Boutons câblés entre GPIO et GND
|
||||
const int buttonPins[8] = {
|
||||
13, 12, 14, 27,
|
||||
26, 25, 33, 32
|
||||
};
|
||||
|
||||
// --------- JOYSTICKS ---------
|
||||
// Joystick gauche
|
||||
const int joyLX = 34;
|
||||
const int joyLY = 35;
|
||||
|
||||
// Joystick droit
|
||||
const int joyRX = 39;
|
||||
const int joyRY = 36;
|
||||
|
||||
// Zone morte pour éviter les tremblements
|
||||
const int deadzone = 180;
|
||||
|
||||
// Convertit ADC ESP32 0-4095 vers axe manette -32767 à 32767
|
||||
int16_t mapJoystick(int pin) {
|
||||
int value = analogRead(pin); // 0 à 4095
|
||||
int centered = value - 2048;
|
||||
|
||||
if (abs(centered) < deadzone) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return map(value, 0, 4095, -32767, 32767);
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
pinMode(buttonPins[i], INPUT_PULLUP);
|
||||
}
|
||||
|
||||
bleGamepad.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (bleGamepad.isConnected()) {
|
||||
|
||||
// Gestion des 8 boutons
|
||||
for (int i = 0; i < 8; i++) {
|
||||
bool pressed = digitalRead(buttonPins[i]) == LOW;
|
||||
|
||||
if (pressed) {
|
||||
bleGamepad.press(i + 1); // boutons 1 à 8
|
||||
} else {
|
||||
bleGamepad.release(i + 1);
|
||||
}
|
||||
}
|
||||
|
||||
// Lecture des joysticks
|
||||
int16_t lx = mapJoystick(joyLX);
|
||||
int16_t ly = mapJoystick(joyLY);
|
||||
int16_t rx = mapJoystick(joyRX);
|
||||
int16_t ry = mapJoystick(joyRY);
|
||||
|
||||
// Envoie des axes
|
||||
// X, Y = joystick gauche
|
||||
// RX, RY = joystick droit
|
||||
bleGamepad.setAxes(lx, ly, 0, rx, ry, 0);
|
||||
|
||||
delay(10);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user