MegaJoy - I only have 14 buttons

I’m using an Arduino Mega with the MegaJoy sketch and I only have 14 of the 32 buttons.

Looking at the code, there is nothing obviously wrong. This is the function that initializes the pins:

void setupPins(void){
  // Set all the digital pins as inputs
  // with the pull-up enabled, except for the 
  // two serial line pins
  for (int i = 2; i <= 54; i++){
    pinMode(i, INPUT);
    digitalWrite(i, HIGH);

And then it creates the array:

 for (int i = 2; i < 54; i++){
    controllerData.buttonArray[(i - 2) / 8] |= (!digitalRead(i)) << ((i - 2) % 8);
  }

I have attached the complete sketch and library.

MegaJoy.h (9.14 KB)

MegaJoyArduinoSample.ino (2 KB)

It should not be causing this problem but your two pieces if code disagree about the last pin being 53 or 54.

Could it be that you are using the UnoJoy driver with the MegaJoy and the UnoJoy doesn't handle the 52 buttons? Maybe there is some way to look at the device properties to see how many buttons are expected.