1. Do not share user accounts! Any account that is shared by another person will be blocked and closed. This means: we will close not only the account that is shared, but also the main account of the user who uses another person's account. We have the ability to detect account sharing, so please do not try to cheat the system. This action will take place on 04/18/2023. Read all forum rules.
    Dismiss Notice
  2. For downloading SimTools plugins you need a Download Package. Get it with virtual coins that you receive for forum activity or Buy Download Package - We have a zero Spam tolerance so read our forum rules first.

    Buy Now a Download Plan!
  3. Do not try to cheat our system and do not post an unnecessary amount of useless posts only to earn credits here. We have a zero spam tolerance policy and this will cause a ban of your user account. Otherwise we wish you a pleasant stay here! Read the forum rules
  4. We have a few rules which you need to read and accept before posting anything here! Following these rules will keep the forum clean and your stay pleasant. Do not follow these rules can lead to permanent exclusion from this website: Read the forum rules.
    Are you a company? Read our company rules

joystick arduino micro pro

Discussion in 'DIY peripherals' started by clabit, May 14, 2020.

  1. clabit

    clabit New Member

    Joined:
    May 12, 2020
    Messages:
    4
    Balance:
    28Coins
    Ratings:
    +1 / 0 / -0
    Hi,

    I built a joystick with 16 buttons and 4 axes
    everything works in the windows control panel, buttons, axis x, axis y, throttle and rudder
    in the game does not see axis (configuration does not associate).
    can you help me?

    Code:
    #include <Keypad.h>
    #include <Joystick.h>
    #define ENABLE_PULLUPS
    #define NUMBUTTONS 16
    #define NUMROWS 4
    #define NUMCOLS 4
    int X1 = A0;
    int Y1 = A1;
    int rudder = A2;
    int throttle = A3;
    byte buttons[NUMROWS][NUMCOLS] = {
      {0, 1, 2, 3},
      {4, 5, 6, 7},
      {8, 9, 10, 11},
      {12, 13, 14, 15},
    };
    byte rowPins[NUMROWS] = {6, 7, 8, 9};
    byte colPins[NUMCOLS] = {2, 3, 4, 5};
    Keypad buttbx = Keypad( makeKeymap(buttons), rowPins, colPins, NUMROWS, NUMCOLS);
    Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID, JOYSTICK_TYPE_GAMEPAD, 16, 0,
                       true, true, false, false, false, false, true, true, false, false, false);
    void setup() {
      Joystick.begin();
      Joystick.setXAxisRange(-512, 512);
      Joystick.setYAxisRange(-512, 512);
      Joystick.setRudderRange(0, 1023);
      Joystick.setThrottleRange(0, 1023);
    }
    void JButtonStates() {
      Joystick.setXAxis(analogRead(X1) - 512);
      Joystick.setYAxis(analogRead(Y1) - 512);
      Joystick.setRudder(analogRead(rudder));
      Joystick.setThrottle(analogRead(throttle));
    }
    void loop() {
      JButtonStates();
      delay(50);
      CheckAllButtons();
    }
    void CheckAllButtons(void)
    {
      if (buttbx.getKeys())
      {
        for (int i = 0; i < LIST_MAX; i++)
        {
          if ( buttbx.key[i].stateChanged )
          {
            switch (buttbx.key[i].kstate)
            {
              case PRESSED:
              case HOLD:
                Joystick.setButton(buttbx.key[i].kchar, 1);
                break;
              case RELEASED:
              case IDLE:
                Joystick.setButton(buttbx.key[i].kchar, 0);
                break;
            }
          }
        }
      }
    }