Pedal switcher problem: Program works with 8, but not with 16

Hi everyone! I’ve been working through a pedal switch using Arduino. Original tutorial here: Link

The good news: when i test it with 8 pedals, it works!

The bad news: when i test it with 16, which is what I need, it gets hung up.

You’ll see in the code below that I’m using the keypad function for this. It goes through the setup functions perfectly. When there’s 8 pedals, it simply stays at the last LCD display in the setup. When it’s 16, it skips the last LCD display message in setup and jumps to the CHOOSE LOOPS/RELAYS section and just kind of stays there in a watery pattern, as if it’s just cycling through it a bunch of times.

I wonder if maybe the code has an issue since it’s a 2-digit number? I’m hoping someone with more experience will see a flaw here that I’m not seeing.

Here’s my code:

#include <LiquidCrystal.h>
#include <Wire.h>
#include <EEPROM.h>
#include <Keypad.h>
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);

const int bankButton = 53; //Pin for Bank Button

const byte rows = 16;
const byte cols = 3;
char keys[rows][cols] = {
  {'a','q','G'},
  {'b','r','H'},
  {'c','s','I'},
  {'d','t','J'},
  {'e','u','K'},
  {'f','v','L'},
  {'g','w','M'},
  {'h','x','N'}, 
  {'i','y','O'},
  {'j','z','P'},
  {'k','A','Q'},
  {'l','B','R'},
  {'m','C','S'},
  {'n','D','T'},
  {'o','E','U'},
  {'p','F','V'} 
};

byte rowPins[rows] = {30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45};
byte colPins[cols] = {48,47,46};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols);
int relayPin[16] = {14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29};
int ledPin[16] = {A0,A1,2,3,4,5,6,7,A8,A9,A10,A11,A12,A13,A14,A15};
int i;
int readOut;
int numberOfPedal = 16;
int bankVariable = 20;
int numberOfBanks = 5;
int bank = 0; //Starting Bank Number
boolean lastBankButton = LOW;
boolean currentBankButton = LOW;

/* SETUP */

void setup()
{
lcd.begin (16,2); 
lcd.print("Line 1");
lcd.setCursor(0,1);
lcd.print("Line 2");

for(i=0; i<numberOfPedal; i++) {
    pinMode(relayPin[i], OUTPUT);
    pinMode(ledPin[i], OUTPUT);
    digitalWrite(relayPin[i],LOW); //turn ON all relays
    digitalWrite(ledPin[i],LOW); //turn ON preset LEDs
   };
   delay(500);
   for(i=0; i<numberOfPedal; i++) {
    pinMode(relayPin[i], OUTPUT); 
    pinMode(ledPin[i], OUTPUT);
    digitalWrite(relayPin[i],HIGH); //turn OFF all relays
    digitalWrite(ledPin[i],HIGH); //turn OFF all preset LEDs
   };
  pinMode(bankButton, INPUT);

delay(3000);

lcd.clear();
lcd.print("Press any preset");
lcd.setCursor(0,1);
lcd.print("to start");
}

/* Bank Button Debounce */

boolean bankdebounce(boolean last) {
  boolean current = digitalRead(bankButton);
  if (last != current) {
    delay(5);
    current = digitalRead(bankButton);
  }
  return current;
}

/* Select Preset and Store */

void memory(int addr, int led) {
  for(i=0; i<numberOfPedal; i++) {
      EEPROM.write((addr) + i, digitalRead(relayPin[i]));
      digitalWrite(ledPin[i], HIGH);
    }
lcd.clear();
lcd.print("Program saved to");
lcd.setCursor(0,1);
lcd.print("Bank ");
lcd.print(bank);
lcd.print(", Preset ");
lcd.print(led + 1);
digitalWrite(ledPin[led], HIGH);
delay(100);
digitalWrite(ledPin[led], LOW);
delay(100);
digitalWrite(ledPin[led], HIGH);
delay(100);
digitalWrite(ledPin[led], LOW);
delay(100);
digitalWrite(ledPin[led], HIGH);
delay(100);
digitalWrite(ledPin[led], LOW);
delay(100);
digitalWrite(ledPin[led], HIGH);
}

/* Choose Loops/Relays */

void writeOut(int relay)
{
  digitalWrite(relayPin[relay], !digitalRead(relayPin[relay]));
  digitalWrite(ledPin[relay], !digitalRead(relayPin[relay]));
  lcd.clear();
  lcd.print("Current Bank: ");
  lcd.print(bank);
  lcd.setCursor(0,1);
  lcd.print("Choose Loops: ");
  lcd.print(relay + 1);
}

/* Use Presets */

void readPreset(int addr, int pcNum, int led) {
  for(i=0; i<numberOfPedal; i++) {
    digitalWrite(relayPin[i], EEPROM.read((addr)+i));
    digitalWrite(ledPin[i], HIGH);
    digitalWrite(ledPin[led], LOW);
   }
   lcd.clear();
   lcd.print("Current Bank: ");
   lcd.print(bank);
   lcd.setCursor(0,1);
   lcd.print("Preset: ");
   lcd.print(led + 1);
}

/* LOOP */

void loop() {

    currentBankButton = bankdebounce(lastBankButton); 
  if (lastBankButton == LOW && currentBankButton == HIGH) {
    bank ++;
    lcd.clear();
    lcd.print("Bank ");
    lcd.print(bank);
    lcd.setCursor(0,1);
    lcd.print("Press Any Preset");
    if (bank >= numberOfBanks) {
      bank = 0;
    }
  }
  lastBankButton = currentBankButton;


  char key = keypad.getKey();
  if(key) { // Check for a valid key.
    switch (key) {
      case 'a': writeOut(0);
      break;
      case 'b': writeOut(1);
      break;
      case 'c': writeOut(2);
      break;
      case 'd': writeOut(3);
      break;
      case 'e': writeOut(4);
      break;
      case 'f': writeOut(5);
      break;
      case 'g': writeOut(6);
      break;
      case 'h': writeOut(7);
      break;
      case 'i': writeOut(8);
      break;
      case 'j': writeOut(9);
      break;
      case 'k': writeOut(10);
      break;
      case 'l': writeOut(11);
      break;
      case 'm': writeOut(12);
      break;
      case 'n': writeOut(13);
      break;
      case 'o': writeOut(14);
      break;
      case 'p': writeOut(15);
      break; 
      case 'q': memory(bank*bankVariable,0);
      break;
      case 'r': memory(100+bank*bankVariable,1);
      break;
      case 's': memory(200+bank*bankVariable,2);
      break;
      case 't': memory(300+bank*bankVariable,3);
      break;
      case 'u': memory(400+bank*bankVariable,4);
      break;
      case 'v': memory(500+bank*bankVariable,5);
      break;
      case 'w': memory(600+bank*bankVariable,6);
      break;
      case 'x': memory(700+bank*bankVariable,7);
      break;
      case 'y': memory(800+bank*bankVariable,8);
      break;
      case 'z': memory(900+bank*bankVariable,9);
      break;
      case 'A': memory(1000+bank*bankVariable,10);
      break;
      case 'B': memory(1100+bank*bankVariable,11);
      break;
      case 'C': memory(1200+bank*bankVariable,12);
      break;
      case 'D': memory(1300+bank*bankVariable,13);
      break;
      case 'E': memory(1400+bank*bankVariable,14);
      break;
      case 'F': memory(1500+bank*bankVariable,15);
      break;
      case 'G': readPreset(bank*bankVariable, 1, 0); 
      break;
      case 'H': readPreset(100+bank*bankVariable, 2, 1);
      break;
      case 'I': readPreset(200+bank*bankVariable, 3, 2);
      break;
      case 'J': readPreset(300+bank*bankVariable, 4, 3);
      break;
      case 'K': readPreset(400+bank*bankVariable, 5, 4);
      break;
      case 'L': readPreset(500+bank*bankVariable, 6, 5);
      break;
      case 'M': readPreset(600+bank*bankVariable, 7, 6);
      break;
      case 'N': readPreset(700+bank*bankVariable, 8, 7);
      break;
      case 'O': readPreset(800+bank*bankVariable, 9, 8);
      break;
      case 'P': readPreset(900+bank*bankVariable, 10, 9);
      break;
      case 'Q': readPreset(1000+bank*bankVariable, 11, 10);
      break;
      case 'R': readPreset(1100+bank*bankVariable, 12, 11);
      break;
      case 'S': readPreset(1200+bank*bankVariable, 13, 12);
      break;
      case 'T': readPreset(1300+bank*bankVariable, 14, 13);
      break;
      case 'U': readPreset(1400+bank*bankVariable, 15, 14);
      break;
      case 'V': readPreset(1500+bank*bankVariable, 16, 15);
      break;
    }
  }
}

Unfortunately, the original poster in instructables isn’t being very responsive (it is a couple years old at this point, after all). Any thoughts?

Hi everyone - I did some troubleshooting here this morning. I started with 8 pedals, then 9, then 10, then 11, then 12.

It appears that the problem starts when I hit 11 pedals. When I put in for 11, everything works, but it does not recognize the 11th pedal. When I put in 12 pedals, it starts to do the infinite looping.

10 and under is fine, but I still need 16 and I just FEEL like I’m missing some small thing…

If I look in the cases, the 10th pedal is represented by a 9, and the 11th is represented by a 10. Could the problem be in that somehow it’s reading 2 digits and something isn’t right? I’m really stumped on this one.

Any insight at all? Thanks in advance!!! :slight_smile:

Here’s my new code:

#include <LiquidCrystal.h>
#include <Wire.h>
#include <EEPROM.h>
#include <Keypad.h>
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);

const int bankButton = 53; //Pin for Bank Button

const byte rows = 11;
const byte cols = 3;
char keys[rows][cols] = {
  {'a','q','7'},
  {'b','r','8'},
  {'c','s','9'},
  {'d','t','0'},
  {'e','u','~'},
  {'f','v','!'},
  {'g','w','@'},
  {'h','x','#'}, 
  {'i','y','

},
 {‘j’,‘z’,’%’},
 {‘k’,‘1’,’^’}/,
 {‘l’,‘2’,’&’},
 {‘m’,‘3’,’
’},
 {‘n’,‘4’,’(’},
 {‘o’,‘5’,’)’},
 {‘p’,‘6’,’+’}*/
};

byte rowPins[rows] = {30,31,32,33,34,35,36,37,38,39,40};//,41,42,43,44,45};
byte colPins[cols] = {46,47,48};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols);
int relayPin[11] = {14,15,16,17,18,19,20,21,22,23,24};//,25};//,26,27,28,29};
int ledPin[8] = {A0,A1,2,3,4,5,6,7};//,A8,A9,A10,A11};//,A12,A13,A14,A15};
int i;
int readOut;

int numberOfPedal = 11;
int bankVariable = 20;
int numberOfBanks = 5;
int bank = 0; //Starting Bank Number
boolean lastBankButton = LOW;
boolean currentBankButton = LOW;

/* SETUP */

void setup() {
lcd.begin (16,2);
lcd.print(“Line 1”);
lcd.setCursor(0,1);
lcd.print(“Line 2”);

for(i=0; i<numberOfPedal; i++) {
   pinMode(relayPin[i], OUTPUT);
   pinMode(ledPin[i], OUTPUT);
   digitalWrite(relayPin[i],LOW); //turn ON all relays
   digitalWrite(ledPin[i],LOW); //turn ON all preset LEDs
  };
  delay(500);
  for(i=0; i<numberOfPedal; i++) {
   pinMode(relayPin[i], OUTPUT);
   pinMode(ledPin[i], OUTPUT);
   digitalWrite(relayPin[i],HIGH); //turn OFF all relays
   digitalWrite(ledPin[i],HIGH); //turn OFF all preset LEDs
  };
 pinMode(bankButton, INPUT);

delay(1000);

lcd.clear();
lcd.print(“Press any preset”);
lcd.setCursor(0,1);
lcd.print(“to start”);
delay(1000);

}

/* Bank Button Debounce */

boolean bankdebounce(boolean last) {
 boolean current = digitalRead(bankButton);
 if (last != current) {
   delay(5);
   current = digitalRead(bankButton);
 }
 return current;
}

/* LOOP */

void loop() {

currentBankButton = bankdebounce(lastBankButton);
 if (lastBankButton == LOW && currentBankButton == HIGH) {
   bank ++;
   lcd.clear();
   lcd.print("Bank ");
   lcd.print(bank);
   lcd.setCursor(0,1);
   lcd.print(“Press Any Preset”);
   if (bank >= numberOfBanks) {
     bank = 0;
   }
 }
 lastBankButton = currentBankButton;

char key = keypad.getKey();
 if(key) { // Check for a valid key.
   switch (key) {
     case ‘a’: writeOut( 0);
     break;
     case ‘b’: writeOut( 1);
     break;
     case ‘c’: writeOut( 2);
     break;
     case ‘d’: writeOut( 3);
     break;
     case ‘e’: writeOut( 4);
     break;
     case ‘f’: writeOut( 5);
     break;
     case ‘g’: writeOut( 6);
     break;
     case ‘h’: writeOut( 7);
     break;
     case ‘i’: writeOut( 8);
     break;
     case ‘j’: writeOut( 9);
     break;
     case ‘k’: writeOut(10);
     break;
     case ‘l’: writeOut(11);
     break;
     case ‘m’: writeOut(12);
     break;
     case ‘n’: writeOut(13);
     break;
     case ‘o’: writeOut(14);
     break;
     case ‘p’: writeOut(15);
     break;
     case ‘q’: memory(100+(bankbankVariable), 0);
     break;
     case ‘r’: memory(200+(bank
bankVariable), 1);
     break;
     case ‘s’: memory(300+(bankbankVariable), 2);
     break;
     case ‘t’: memory(400+(bank
bankVariable), 3);
     break;
     case ‘u’: memory(500+(bankbankVariable), 4);
     break;
     case ‘v’: memory(600+(bank
bankVariable), 5);
     break;
     case ‘w’: memory(700+(bankbankVariable), 6);
     break;
     case ‘x’: memory(800+(bank
bankVariable), 7);
     break;
     case ‘y’: memory(900+(bankbankVariable), 8);
     break;
     case ‘z’: memory(1000+(bank
bankVariable), 9);
     break;
     case ‘1’: memory(1100+(bankbankVariable),10);
     break;
     case ‘2’: memory(1200+(bank
bankVariable),11);
     break;
     case ‘3’: memory(1300+(bankbankVariable),12);
     break;
     case ‘4’: memory(1400+(bank
bankVariable),13);
     break;
     case ‘5’: memory(1500+(bankbankVariable),14);
     break;
     case ‘6’: memory(1600+(bank
bankVariable),15);
     break;
     case ‘7’: readPreset(100+(bankbankVariable), 0);
     break;
     case ‘8’: readPreset(200+(bank
bankVariable), 1);
     break;
     case ‘9’: readPreset(300+(bankbankVariable), 2);
     break;
     case ‘0’: readPreset(400+(bank
bankVariable), 3);
     break;
     case ‘~’: readPreset(500+(bankbankVariable), 4);
     break;
     case ‘!’: readPreset(600+(bank
bankVariable), 5);
     break;
     case ‘@’: readPreset(700+(bankbankVariable), 6);
     break;
     case ‘#’: readPreset(800+(bank
bankVariable), 7);
     break;
     case ’


: readPreset(900+(bank*bankVariable), 8);
      break;
      case '%': readPreset(1000+(bank*bankVariable), 9);
      break;
      case '^': readPreset(1100+(bank*bankVariable),10);
      break;
      case '&': readPreset(1200+(bank*bankVariable),11);
      break;
      case '*': readPreset(1300+(bank*bankVariable),12);
      break;
      case '(': readPreset(1400+(bank*bankVariable),13);
      break;
      case ')': readPreset(1500+(bank*bankVariable),14);
      break;
      case '+': readPreset(1600+(bank*bankVariable),15);
      break;
    }
  }
}

/* Use Presets */

void readPreset(int addr, int led) {
  for(i=0; i<numberOfPedal; i++) {
    digitalWrite(relayPin[i], EEPROM.read((addr)+i));
    digitalWrite(ledPin[i], HIGH);
    digitalWrite(ledPin[led], LOW);
   }
   lcd.clear();
   lcd.print("Current Bank: ");
   lcd.print(bank);
   lcd.setCursor(0,1);
   lcd.print("Preset: ");
   lcd.print(led + 1);
}

/* Select Preset and Store */

void memory(int addr, int led) {
  for(i=0; i<numberOfPedal; i++) {
      EEPROM.write((addr) + i, digitalRead(relayPin[i]));
      digitalWrite(ledPin[i], HIGH);
    }
lcd.clear();
lcd.print("Program saved to");
lcd.setCursor(0,1);
lcd.print("Bank ");
lcd.print(bank);
lcd.print(", Preset ");
lcd.print(led + 1);
digitalWrite(ledPin[led], HIGH);
delay(100);
digitalWrite(ledPin[led], LOW);
delay(100);
digitalWrite(ledPin[led], HIGH);
delay(100);
digitalWrite(ledPin[led], LOW);
delay(100);
digitalWrite(ledPin[led], HIGH);
delay(100);
digitalWrite(ledPin[led], LOW);
delay(100);
digitalWrite(ledPin[led], HIGH);
lcd.clear();
}

/* Choose Loops/Relays */

void writeOut(int relay)
{
  digitalWrite(relayPin[relay], !digitalRead(relayPin[relay]));
  //digitalWrite(ledPin[relay], !digitalRead(relayPin[relay]));
  lcd.clear();
  lcd.print("Current Bank: ");
  lcd.print(bank);
  lcd.setCursor(0,1);
  lcd.print("Choose Loops: ");
  lcd.print(relay + 1);
}