jfedor2 / flatbox

Low profile hitbox-layout fightstick
662 stars 135 forks source link

start button not getting detected rev1.1 #26

Closed jh0nny2k closed 1 year ago

jh0nny2k commented 1 year ago

Hi,

I have soldered 2 pcb's and on both of them the start buttons is not getting detected. Being that anyway i have to configure these in steam i just skipped the button in the configuration process. The button presses are also not registered on the micro itself. for all other buttons the led flashes for the start button there is no flash.

Thing is i connected the button directly to the pin (ran a wire) and it still didn't register, Wich is weird. Any suggestions?

Side question, can't the micro be coded to be detected as a 360 controller by windows?

Kind regards

jfedor2 commented 1 year ago

I don't really have any ideas. Does this happen on two different Pro Micros? Do the other pins work as they should? Do you have "Pro Micro" selected in the boards menu?

As for emulating a 360 controller, there are firmwares that run on a Pro Micro and support XInput. I haven't tried them, but here's an example: https://github.com/fluffymadness/ATMega32U4-XINPUT-Fightstick

jh0nny2k commented 1 year ago

/*

include

// Setup const boolean UseLeftJoystick = false; // set to true to enable left joystick const boolean InvertLeftYAxis = false; // set to true to use inverted left joy Y

const boolean UseRightJoystick = false; // set to true to enable right joystick const boolean InvertRightYAxis = false; // set to true to use inverted right joy Y

const boolean UseTriggerButtons = true; // set to false if using analog triggers

const int ADC_Max = 1023; // 10 bit

// Joystick Pins const int Pin_LeftJoyX = 0; const int Pin_LeftJoyY = 0; const int Pin_RightJoyX = 1; const int Pin_RightJoyY = 1;

// Trigger Pins const int Pin_TriggerL = A2; const int Pin_TriggerR = A0;

// Button Pins const int Pin_ButtonA = 10; const int Pin_ButtonB = 14; const int Pin_ButtonX = 16; const int Pin_ButtonY = 15;

const int Pin_ButtonLB = A3; const int Pin_ButtonRB = A1;

const int Pin_ButtonBack = 2; const int Pin_ButtonStart = 3;

const int Pin_ButtonL3 = 4; const int Pin_ButtonR3 = 5;

// Directional Pad Pins const int Pin_DpadUp = 9; const int Pin_DpadDown = 7; const int Pin_DpadLeft = 6; const int Pin_DpadRight = 8;

void setup() { // If using buttons for the triggers, use internal pull-up resistors if (UseTriggerButtons == true) { pinMode(Pin_TriggerL, INPUT_PULLUP); pinMode(Pin_TriggerR, INPUT_PULLUP); } // If using potentiometers for the triggers, set range else { XInput.setTriggerRange(0, ADC_Max); }

// Set buttons as inputs, using internal pull-up resistors
pinMode(Pin_ButtonA, INPUT_PULLUP);
pinMode(Pin_ButtonB, INPUT_PULLUP);
pinMode(Pin_ButtonX, INPUT_PULLUP);
pinMode(Pin_ButtonY, INPUT_PULLUP);

pinMode(Pin_ButtonLB, INPUT_PULLUP);
pinMode(Pin_ButtonRB, INPUT_PULLUP);

pinMode(Pin_ButtonBack, INPUT_PULLUP);
pinMode(Pin_ButtonStart, INPUT_PULLUP);

pinMode(Pin_ButtonL3, INPUT_PULLUP);
pinMode(Pin_ButtonR3, INPUT_PULLUP);

pinMode(Pin_DpadUp, INPUT_PULLUP);
pinMode(Pin_DpadDown, INPUT_PULLUP);
pinMode(Pin_DpadLeft, INPUT_PULLUP);
pinMode(Pin_DpadRight, INPUT_PULLUP);

XInput.setJoystickRange(0, ADC_Max);  // Set joystick range to the ADC
XInput.setAutoSend(false);  // Wait for all controls before sending

XInput.begin();

}

void loop() { // Read pin values and store in variables // (Note the "!" to invert the state, because LOW = pressed) boolean buttonA = !digitalRead(Pin_ButtonA); boolean buttonB = !digitalRead(Pin_ButtonB); boolean buttonX = !digitalRead(Pin_ButtonX); boolean buttonY = !digitalRead(Pin_ButtonY);

boolean buttonLB = !digitalRead(Pin_ButtonLB);
boolean buttonRB = !digitalRead(Pin_ButtonRB);

boolean buttonBack  = !digitalRead(Pin_ButtonBack);
boolean buttonStart = !digitalRead(Pin_ButtonStart);

boolean buttonL3 = !digitalRead(Pin_ButtonL3);
boolean buttonR3 = !digitalRead(Pin_ButtonR3);

boolean dpadUp    = !digitalRead(Pin_DpadUp);
boolean dpadDown  = !digitalRead(Pin_DpadDown);
boolean dpadLeft  = !digitalRead(Pin_DpadLeft);
boolean dpadRight = !digitalRead(Pin_DpadRight);

// Set XInput buttons
XInput.setButton(BUTTON_A, buttonA);
XInput.setButton(BUTTON_B, buttonB);
XInput.setButton(BUTTON_X, buttonX);
XInput.setButton(BUTTON_Y, buttonY);

XInput.setButton(BUTTON_LB, buttonLB);
XInput.setButton(BUTTON_RB, buttonRB);

XInput.setButton(BUTTON_BACK, buttonBack);
XInput.setButton(BUTTON_START, buttonStart);

XInput.setButton(BUTTON_L3, buttonL3);
XInput.setButton(BUTTON_R3, buttonR3);

// Set XInput DPAD values
XInput.setDpad(dpadUp, dpadDown, dpadLeft, dpadRight);

// Set XInput trigger values
if (UseTriggerButtons == true) {
    // Read trigger buttons
    boolean triggerLeft  = !digitalRead(Pin_TriggerL);
    boolean triggerRight = !digitalRead(Pin_TriggerR);

    // Set the triggers as if they were buttons
    XInput.setButton(TRIGGER_LEFT, triggerLeft);
    XInput.setButton(TRIGGER_RIGHT, triggerRight);
}
else {
    // Read trigger potentiometer values
    int triggerLeft  = analogRead(Pin_TriggerL);
    int triggerRight = analogRead(Pin_TriggerR);

    // Set the trigger values as analog
    XInput.setTrigger(TRIGGER_LEFT, triggerLeft);
    XInput.setTrigger(TRIGGER_RIGHT, triggerRight);
}

// Set left joystick
if (UseLeftJoystick == true) {
    int leftJoyX = analogRead(Pin_LeftJoyX);
    int leftJoyY = analogRead(Pin_LeftJoyY);

    // White lie here... most generic joysticks are typically
    // inverted by default. If the "Invert" variable is false
    // then we'll take the opposite value with 'not' (!).
    boolean invert = !InvertLeftYAxis;

    XInput.setJoystickX(JOY_LEFT, leftJoyX);
    XInput.setJoystickY(JOY_LEFT, leftJoyY, invert);
}

// Set right joystick
if (UseRightJoystick == true) {
    int rightJoyX = analogRead(Pin_RightJoyX);
    int rightJoyY = analogRead(Pin_RightJoyY);

    boolean invert = !InvertRightYAxis;

    XInput.setJoystickX(JOY_RIGHT, rightJoyX);
    XInput.setJoystickY(JOY_RIGHT, rightJoyY, invert);
}

// Send control data to the computer
XInput.send();

}

jh0nny2k commented 1 year ago

I modified the above to make it work. Till now it works okey, no complaints. i just lost the pin 0 and 1 buttons, not sure what i could possibly map on them. plus not sure how to map the Xbox button as i just modified the pins in the above programing :)