Arduino micro Button box programming

Hello,

I’ve been trying to get my button box to work. I used the code from a youtube tutorial and altered it for my button box but it wont work. Hardware wise I made columns and rows. Rows connected to A5 to A0 and pin 12 and columns connected to pin 10,9,8. I don’t get an error in the code but when I try to assign buttons in-game they don’t react.

Thanks in advance!

#include <Keypad.h>
#include <Joystick.h>

#define NUMBUTTONS 16
#define NUMROWS 8
#define NUMCOLS 3

byte buttons[NUMROWS][NUMCOLS] = {
  {0,1},
  {2,3},
  {4,5},
  {6,7},
  {8,9},
  {10,11,12},
  {13,14},
  {15},
  };

byte rowPins[NUMROWS] = {19,18,17,16,15,14,12}; 
byte colPins[NUMCOLS] = {10,9,8}; 

Keypad buttbx = Keypad( makeKeymap(buttons), rowPins, colPins, NUMROWS, NUMCOLS); 

Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID, 
  JOYSTICK_TYPE_JOYSTICK, 32, 0,
  false, false, false, false, false, false,
  false, false, false, false, false);

void setup() {
  Joystick.begin();}


  void loop() { 

  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;
            }
           }   
         }
     }
}

Please read the "how to use this forum-please read" stickies.

groundFungus: Please read the "how to use this forum-please read" stickies.

Thanks for the help!

Is that sarcasm? Pictures of code are useless. I can't put it into a text editor so that it is easier to examine. I can't put it into the IDE to see if it will compile or what may be wrong. I have to do that because you don't give a clue as to your problem. So read #7 on how to post code so it is easy to view, copy and paste and #11 to see what we need to be able to help you.

Arduinonuub: but it wont work.

Honestly, how do you expect to get any help with for-crap problem description like that?

groundFungus: Is that sarcasm? Pictures of code are useless. I can't put it into a text editor so that it is easier to examine. I can't put it into the IDE to see if it will compile or what may be wrong. I have to do that because you don't give a clue as to your problem. So read #7 on how to post code so it is easy to view, copy and paste and #11 to see what we need to be able to help you.

If you think that is sarcasm wait till you see my real sarcasm :D Changed the post!

The only clue that we have is that it won't work. We cannot know what that means. Please describe what the code is actually doing and how that differs from what you want. If there are errors, post the complete error message in code tags.

Which joystick library are you using? Which Arduino board are you using?

byte buttons[NUMROWS][NUMCOLS] =
{
  {0, 1},
  {2, 3},
  {4, 5},
  {6, 7},
  {8, 9},
  {10, 11, 12},
  {13, 14},
  {15},
};

byte rowPins[NUMROWS] = {19, 18, 17, 16, 15, 14, 12};
byte colPins[NUMCOLS] = {10, 9, 8};

Looks wrong.

8 rows of values but only 7 row pins ?

groundFungus:
The only clue that we have is that it won’t work. We cannot know what that means. Please describe what the code is actually doing and how that differs from what you want. If there are errors, post the complete error message in code tags.

Which joystick library are you using?
Which Arduino board are you using?

So when I upload the code to my arduino Micro I have no errors. When I try to assign buttons ingame some work and others dont. I checked all the wiring so it has to be a fault in the code. It seems that the buttons connected to the connections on my micro A0 to A5 don’t work. I’ll check the library in a minute. It also happens that some buttons have the same assignment even though they work on a different connection on the micro. For example let’s say the buttons are assigned to a letter. In my case button 1 aswell as button 2 give the same letter.

Edit: This is the joystick library GitHub - MHeironimus/ArduinoJoystickLibrary: An Arduino library that adds one or more joysticks to the list of HID devices an Arduino Leonardo or Arduino Micro can support.

UKHeliBob: 8 rows of values but only 7 row pins ?

Yeah I know, tried it with 7 aswell but same results.

I don't use the keypad library. It has to output power on the columns to read the rows, doesn't it? Does it set the pinMode itself or should you do that in setup()?

MorganS: I don't use the keypad library. It has to output power on the columns to read the rows, doesn't it? Does it set the pinMode itself or should you do that in setup()?

I don't know, i'm not good at this stuff at all. I tried to follow a youtube tutorial but quickly saw I had to do some programming on my side because I have a different button layout. His was 5x5 and mine is 7x3. He was also using an arduino pro micro so the pins were different aswell.

Start with a simple sketch that reads 3 rows of 3 buttons and forget the joystick stuff until you have the keypad working. Once you have 3 by 3 working extend it to the size that you want and test again. Try using the A* names for the analogue pins