im trying to make a wii pro controller to nintendo switch an the two joysticks aren't working as planed heres my code.
#include "SwitchJoystick.h"
#include <NintendoExtensionCtrl.h>
ClassicController classic;
// Create Joystick
SwitchJoystick_ Joystick;
int LXhome;
int LYhome;
int RXhome;
int RYhome;
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = { 6, 7, 8, 9}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {10, 11, 12, 13}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup() {
Serial.begin(115200);
Joystick.begin(false);
classic.begin();
while (!classic.connect()) {
Serial.println("Classic Controller not detected!");
delay(1000);
}
LXhome = classic.leftJoyX();
LYhome = classic.leftJoyY();
RXhome = classic.rightJoyX();
RYhome = classic.rightJoyY();
}
int rightStick(uint8_t input) {
if (input > 24)
return 127;
else if (input > 20)
return 64;
else if (input < 8)
return -127;
else if (input < 12)
return -64;
return 0;
}
int leftStick(uint8_t input) {
if (input > 45)
return 127;
else if (input > 35)
return 64;
else if (input < 15)
return -127;
else if (input < 25)
return -64;
return 0;
}
void loop() {
char customKey = customKeypad.getKey();
if (customKey == '1'){
}else if(customKey == '2'){
}else if(customKey == '3'){
}else if(customKey == 'A'){
}else if(customKey == '4'){
}else if(customKey == '5'){
}else if(customKey == '6'){
}else if(customKey == 'B'){
}else if(customKey == '7'){
}else if(customKey == '8'){
}else if(customKey == '9'){
}else if(customKey == 'C'){
Joystick.pressButton(13); // capture
while(true){
if (customKey != NO_KEY){
Joystick.releaseButton(13); // capture
break;
}
}
}else if(customKey == '*'){
}else if(customKey == '0'){
}else if(customKey == '#'){
}else if(customKey == 'D'){
}
boolean success = classic.update();
if (!success) {
Serial.println("Controller disconnected!");
classic.connect();
//delay(100);
} else {
//classic.printDebug();
Joystick.setButton(12, classic.buttonHome());
Joystick.setButton(2, classic.buttonA());
Joystick.setButton(1, classic.buttonB());
Joystick.setButton(3, classic.buttonX());
Joystick.setButton(0, classic.buttonY());
Joystick.setButton(4, classic.buttonL());
Joystick.setButton(5, classic.buttonR());
Joystick.setButton(6, classic.buttonZL());
Joystick.setButton(7, classic.buttonZR());
Joystick.setButton(9, classic.buttonPlus());
Joystick.setButton(8, classic.buttonMinus());
if((classic.leftJoyX() <= LXhome + 10 && classic.leftJoyX() >= LXhome - 10) && (classic.leftJoyY() <= LYhome + 10 && classic.leftJoyY() >= LYhome - 10)){
Joystick.setXAxis(leftStick(LXhome));
Joystick.setYAxis(leftStick(LYhome));
}else if(classic.leftJoyX() > LXhome){
Joystick.setXAxis(leftStick(LXhome + classic.leftJoyX()));
}else if(classic.leftJoyX() < LXhome){
Joystick.setYAxis(leftStick(LXhome - classic.leftJoyX()));
}else if(classic.leftJoyY() > LYhome){
Joystick.setXAxis(leftStick(LYhome + classic.leftJoyY()));
}else if(classic.leftJoyY() < LYhome){
Joystick.setYAxis(leftStick(LYhome - classic.leftJoyY()));
}
if((classic.rightJoyX() <= RXhome + 10 || classic.rightJoyX() >= RXhome - 10) && (classic.rightJoyY() <= RYhome + 10 || classic.rightJoyY() >= RYhome - 10)){
Joystick.setZAxis(leftStick(RXhome));
Joystick.setRzAxis(leftStick(RYhome));
}else if(classic.rightJoyX() > RXhome){
Joystick.setZAxis(leftStick(RXhome + classic.rightJoyX()));
}else if(classic.rightJoyX() < RXhome){
Joystick.setRzAxis(leftStick(RXhome - classic.rightJoyX()));
}else if(classic.rightJoyY() > RYhome){
Joystick.setZAxis(leftStick(RYhome + classic.rightJoyY()));
}else if(classic.rightJoyY() < RYhome){
Joystick.setRzAxis(leftStick(RYhome - classic.rightJoyY()));
}
if (classic.dpadUp()) {
if (classic.dpadLeft()){
Joystick.setHatSwitch(135);
}else if (classic.dpadRight()){
Joystick.setHatSwitch(45);
}else{
Joystick.setHatSwitch(0);
}
} else if (classic.dpadDown()) {
if (classic.dpadLeft()){
Joystick.setHatSwitch(225);
}else if (classic.dpadRight()){
Joystick.setHatSwitch(135);
}else{
Joystick.setHatSwitch(180);
}
} else if (classic.dpadRight()){
Joystick.setHatSwitch(90);
}else if (classic.dpadLeft()){
Joystick.setHatSwitch(270);
}else{
Joystick.setHatSwitch(-1);
}
}
Joystick.sendState();
delay(100);
}
i need help and I don't know what to do.