Button box code help

Hey all,

I built a button box, everything is wired up and all of the push buttons work using the code below, but for some reason my rotary encoders are not working, well 3 out of the 4 are not working. Is there something in my code that I messed up? Should rotary encoders not be linked to analog pins? Any guidance would be appreciated.

#include <Keypad.h>
#include <Keyboard.h>
#include <SimpleRotary.h>

#define NUMROWS 6
#define NUMCOLS 4

const int ModPin = A0;
int ModState = 0; 

//define the symbols on the buttons of the keypads
char buttons[NUMROWS][NUMCOLS] = {
  {'7','5','3','1'},
  {'6','4','2','0'},
  {'r','e','w','q'},
  {'i','u','y','t'},
  {'f','d','s','a'},
  {'p','j','h','g'},
};

char buttonsMod[NUMROWS][NUMCOLS] = {
  {'7','5','3','1'},
  {'6','4','2','0'},
  {0xC9,0xC7,0xC5,0xC3},
  {0xC8,0xC6,0xC4,0xC2},
  {'f','d','s','a'},
  {'p','j','h','g'},
};



byte rowPins[NUMROWS] = {13,12,11,10,9,8}; //connect to the row pinouts of the keypad
byte colPins[NUMCOLS] = {7,6,5,4}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad buttbx = Keypad( makeKeymap(buttons), rowPins, colPins, NUMROWS, NUMCOLS); 
Keypad buttbxMod = Keypad( makeKeymap(buttonsMod), rowPins, colPins, NUMROWS, NUMCOLS); 

SimpleRotary A(1,2,3);
SimpleRotary B(1,2,3);
SimpleRotary C(1,2,3);
SimpleRotary D(1,2,3);

void setup() {
  Keyboard.begin();
  pinMode(ModPin, INPUT_PULLUP);
}



void loop() { 
ModState = digitalRead(ModPin);
if (ModState == HIGH) {
    CheckAllButtons();
  } else {
CheckAllButtonsMod();
  }
  

byte i;

  // 0 = not turning, 1 = CW, 2 = CCW
  i = A.rotate();

  if ( i == 1 ) {
    Keyboard.press(KEY_LEFT_ARROW);
    delay(150);
    Keyboard.releaseAll();
  }

  if ( i == 2 ) {
    Keyboard.press(KEY_RIGHT_ARROW);
    delay(150);
    Keyboard.releaseAll();
  }
i = B.rotate();
if ( i == 1 ) {
    Keyboard.press(KEY_LEFT_ARROW);
    delay(150);
    Keyboard.releaseAll();
  }

  if ( i == 2 ) {
    Keyboard.press(KEY_RIGHT_ARROW);
    delay(150);
    Keyboard.releaseAll();
  }
i = B.rotate();
if ( i == 1 ) {
    Keyboard.press(KEY_LEFT_ARROW);
    delay(150);
    Keyboard.releaseAll();
  }

  if ( i == 2 ) {
    Keyboard.press(KEY_RIGHT_ARROW);
    delay(150);
    Keyboard.releaseAll();
  }
  i = B.rotate();
if ( i == 1 ) {
    Keyboard.press(KEY_LEFT_ARROW);
    delay(150);
    Keyboard.releaseAll();
  }

  if ( i == 2 ) {
    Keyboard.press(KEY_RIGHT_ARROW);
    delay(150);
    Keyboard.releaseAll();
  }
}


void CheckAllButtons(void) {
  char key = buttbx.getKey();
  if (key != NO_KEY)  {
    Keyboard.press(key);
    delay(150);
    Keyboard.releaseAll();
  }//Keyboard.write(key);
}

void CheckAllButtonsMod(void) {
  char key = buttbxMod.getKey();
  if (key != NO_KEY)  {
    Keyboard.press(key);
    delay(150);
    Keyboard.releaseAll();
  }//Keyboard.write(key);
}

It looks like you have declared all your encoders to be on the same pins (1,2 and 3).

Indeed, that and i never checking C or D, seems like some of the problems have been resolved now, nee code below:

#include <Keypad.h>
#include <Keyboard.h>
#include <SimpleRotary.h>

#define NUMROWS 6
#define NUMCOLS 4

const int ModPin = A0;
int ModState = 0; 

//define the symbols on the buttons of the keypads
char buttons[NUMROWS][NUMCOLS] = {
  {'7','5','3','1'},
  {'6','4','2','0'},
  {'r','e','w','q'},
  {'i','u','y','t'},
  {'f','d','s','a'},
  {'p','j','h','g'},
};

char buttonsMod[NUMROWS][NUMCOLS] = {
  {'7','5','3','1'},
  {'6','4','2','0'},
  {0xC9,0xC7,0xC5,0xC3},
  {0xC8,0xC6,0xC4,0xC2},
  {'f','d','s','a'},
  {'p','j','h','g'},
};



byte rowPins[NUMROWS] = {13,12,11,10,9,8}; //connect to the row pinouts of the keypad
byte colPins[NUMCOLS] = {7,6,5,4}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad buttbx = Keypad( makeKeymap(buttons), rowPins, colPins, NUMROWS, NUMCOLS); 
Keypad buttbxMod = Keypad( makeKeymap(buttonsMod), rowPins, colPins, NUMROWS, NUMCOLS); 

SimpleRotary RotaryA(1,2,3);
SimpleRotary RotaryB(0,A5,3);
SimpleRotary RotaryC(A4,A3,3);
SimpleRotary RotaryD(A2,A1,3);

void setup() {
  Keyboard.begin();
  pinMode(ModPin, INPUT_PULLUP);
}



void loop() { 
ModState = digitalRead(ModPin);
  if (ModState == HIGH) {
    CheckAllButtons();
  } else {
  CheckAllButtonsMod();
  }
  

byte i;

  // 0 = not turning, 1 = CW, 2 = CCW
  
  i = RotaryA.rotate();

  if ( i == 1 ) {
    Keyboard.press(KEY_LEFT_ARROW);
    delay(150);
    Keyboard.releaseAll();
  }
  if ( i == 2 ) {
    Keyboard.press(KEY_RIGHT_ARROW);
    delay(150);
    Keyboard.releaseAll();
  }

  i = RotaryB.rotate();
  
  if ( i == 1 ) {
    Keyboard.press(KEY_LEFT_ARROW);
    delay(150);
    Keyboard.releaseAll();
  }
  if ( i == 2 ) {
    Keyboard.press(KEY_RIGHT_ARROW);
    delay(150);
    Keyboard.releaseAll();
  }
  
  i = RotaryC.rotate();
  
  if ( i == 1 ) {
    Keyboard.press(KEY_LEFT_ARROW);
    delay(150);
    Keyboard.releaseAll();
  }
  if ( i == 2 ) {
    Keyboard.press(KEY_RIGHT_ARROW);
    delay(150);
    Keyboard.releaseAll();
  }
  
  i = RotaryD.rotate();
  
  if ( i == 1 ) {
    Keyboard.press(KEY_LEFT_ARROW);
    delay(150);
    Keyboard.releaseAll();
  }
  if ( i == 2 ) {
    Keyboard.press(KEY_RIGHT_ARROW);
    delay(150);
    Keyboard.releaseAll();
  }
}


void CheckAllButtons(void) {
  char key = buttbx.getKey();
  if (key != NO_KEY)  {
    Keyboard.press(key);
    delay(150);
    Keyboard.releaseAll();
  }//Keyboard.write(key);
}

void CheckAllButtonsMod(void) {
  char key = buttbxMod.getKey();
  if (key != NO_KEY)  {
    Keyboard.press(key);
    delay(150);
    Keyboard.releaseAll();
  }//Keyboard.write(key);
}

Thank you for helping