How to enter 3 digit numbers with footswitches (0 to 9 buttons) ?

Project: Midi Foot Controller.

Objective: The prototype is already working, but it is limited to fixed functions for each footswitch (e.g.: preset up/down, looper control, tuner etc.) Now I want to implement a configuration menu to allow personalizing the function of each individual switch e.g.: CC (Control Change) and store the settings on EEPROM.

Challenge: currently I can only assign CC commands from 0 to 9 by pressing a footswitch. I would like to know how to enter numbers from 0 to 127 (by pressing the buttons numbered 0 to 9). I am stuck there.

I am using switches to identify the pressed button and assign a number. Perhaps my approach is not correct. I would appreciate any advice. Thank you!

I am trying to post all the code related to the configuration menus, but it exceeds the allowed number of characters. Here is a portion:

void assignParameter1 (int button) { // assign aprameter 1 to the command of the selected button
  assignParameter1TFT (button); // update display data
  while (asignParameter1Activated == true) {
    for (byte currentSwitch = 0; currentSwitch < NUM_BUTTONS; currentSwitch++) {
      Buttons[currentSwitch].read();
      if (Buttons[currentSwitch].wasPressed()) {
        Serial.println("-----------");
        Serial.print("assignParameter1() - Switch "); Serial.print(currentSwitch + 1); Serial.println(" pressed.");
        switch ( currentSwitch ) {
          case 0: //button1
            buttonParameter1 [button - 1]  = 1;
            break;
          case 1: //button2
            buttonParameter1 [button - 1]  = 2;
            break;
          case 2: //button3
            buttonParameter1 [button - 1]  = 3;
            break;
          case 3: //button4
            buttonParameter1 [button - 1]  = 4;
            break;
          case 4: //button5
            buttonParameter1 [button - 1]  = 5;
            break;
          case 5: //button6
            buttonParameter1 [button - 1]  = 6;
            break;
          case 6: //button7
            buttonParameter1 [button - 1]  = 7;
            break;
          case 7: //button8
            buttonParameter1 [button - 1]  = 8;
            break;
          case 8: //button9
            buttonParameter1 [button - 1]  = 9;
            break;
          case 9: //button10
            buttonParameter1 [button - 1]  = 0;
            break;
          case 10: //button11 - EXIT
            layoutSetupMenutoTFT();
            asignParameter1Activated = false;  //Back to setupMenu()
            break;
        }
        Serial.print("button = "); Serial.println(button);
        // button goes from 1 to NUM_BUTTONS. We want to start recording at EEPROM add. 2+NUM_BUTTONS
        saveToEEPROM((button + 1 + NUM_BUTTONS), (buttonParameter1 [button - 1])); // save to EEMPROM addresses 2+NUM_BUTTONS to 2+2*NUM_BUTTONS
        Serial.print("Saved at EEPROM add: "); Serial.print(button + 1 + NUM_BUTTONS); Serial.print(" Value: "); Serial.println(buttonParameter1 [button - 1]);
        Serial.print("buttonParameter1 {");
        for (byte i = 0; i <= (NUM_BUTTONS - 1); i++) {
          Serial.print(buttonParameter1 [i]); Serial.print(",");
        }
        Serial.println("}");
      }
    }
  }
}

The easiest method would be to always require 3 digits be input (‘000’ to ‘999’) and then make sure to filter out any values greater than 127.

Something like this:

int readDigits() {
  int result = 0;
  const byte maxDigits = 3;

  for ( int digit = 0; digit < maxDigits; digit++ ) {
    for (int i = 0; i < NUM_BUTTONS; i++) {
      Buttons[i].read();
      if (Buttons[i].wasPressed()) {
        result = result * 10 + i;
        while ( !Buttons[i].wasReleased() ) {
          delay(10);
          Buttons[i].read();
        }
      }
    }
  }
  if (result > 127 ) {
    result = -1;  // or whatever you want for out of range
  }
  return result;
}

I don’t know which Button library you are using, but I’m guessing you will need some call in there to determine when the button is released so the code does’t read the same press twice.

Thank you! I am going to try it. It looks simple once I see the solution :slight_smile:

I am using JChristensen JC_Button library