Hi,
I loaded the following code on a Leonardo, trying to emulate a gamecontroller, connected the Leonardo to my W10/64 laptop via usb and tried the w10 Gamecontroller setup. Nothing, the W10 gamecontroller didn`t find any controllere.
When I tried my PS4ds it was found right away.
Can someone help me?
#include <XInput.h>
// Input Pins
const uint8_t Pin_Joystick = A0; // Turn left/right
const uint8_t Pin_ButtonA = 2; // Jump
const uint8_t Pin_TriggerR = 3; // Accelerate
// Output Pins
const uint8_t Pin_LED = LED_BUILTIN;
// Analog Input Range
const int AnalogRead_Max = 1023; // 10-bit ADC
void setup() {
// Set input pin modes
pinMode(Pin_ButtonA, INPUT_PULLUP);
pinMode(Pin_TriggerR, INPUT_PULLUP);
// Set output pin mode
pinMode(Pin_LED, OUTPUT);
digitalWrite(Pin_LED, LOW); // Turn 'off'
// Setup library
XInput.setRange(JOY_LEFT, 0, AnalogRead_Max);
XInput.begin(); // starting auto usb converstaion now
}
void loop() {
// Read pin states
boolean pressA = !digitalRead(Pin_ButtonA);
boolean pressTrigger = !digitalRead(Pin_TriggerR);
int joystickValue = analogRead(Pin_Joystick);
// Set button and trigger states
XInput.setButton(BUTTON_A, pressA);
XInput.setButton(TRIGGER_RIGHT, pressTrigger);
XInput.setJoystick(JOY_LEFT, joystickValue, AnalogRead_Max / 2); // move x, leave y centered
// Get rumble value
uint16_t rumble = XInput.getRumble();
// If controller is rumbling, turn on LED
if (rumble > 0) {
digitalWrite(Pin_LED, HIGH);
}
else {
digitalWrite(Pin_LED, LOW);
}
}