Keypad Help

The following code works perfectly to activate 1-9 servos by entering single digits on the keypad. My problem is I would like to be able to control more than 9 servos but I don't know how to write the code to except double digit entries (10-99). Any help with this problem would be greatly appreciated.

PRH3

/*Relay-St Louis Staging Yard
  Sets switches to selected track
  Turns on a relay in a cascade configuration.

  modified Jan 2, 2017
  by Carl Schoeneberg

*/
//Libraries and required code
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
#include <Keypad.h>

const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] =
  {{'1','2','3'},
   {'4','5','6'},
   {'7','8','9'},
   {'*','0','#'}};
byte rowPins[ROWS] = {10,11,12,13};
byte colPins[COLS] = {7,8,9};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, 

ROWS, COLS );

//end of required code

// the setup function runs once when you press reset or power the board

void setup() 
{
  Serial.begin (9600);
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(A0, OUTPUT);
  pinMode(A1, OUTPUT);
  pinMode(A2, OUTPUT);
  pinMode(A3, OUTPUT);
  pwm.begin();  
  pwm.setPWMFreq(60);
  Serial.begin(9600);
  Serial.println("16 channel Servo Test");
  yield();
  //int S1S = 250;
  //int S1L = 300;
  pwm.setPWM(1, 0, 250);
  delay(100);
  pwm.setPWM(3, 0, 245);
  delay(100);
  //pwm.setPWM(5, 0, 400);
  //delay(100);
  //pwm.setPWM(8, 0, 400);
  digitalWrite(2, LOW);
  digitalWrite(3, HIGH);
  digitalWrite(4, HIGH);
  digitalWrite(5, HIGH);
  digitalWrite(A0, HIGH);
  digitalWrite(A1, HIGH);
  digitalWrite(A2, HIGH);
  digitalWrite(A3, HIGH);
}

// the loop function runs over and over again forever

void loop()
{
  char key = keypad.getKey();  //Press a keypad key
     Serial.print(key);
    switch(key)  //switch-case looks for numerals 1-9, other are ignored
    {             
                  //the selected case positions switches with pwm.set
                  //and then the required relay will be tripped to power a single 

track
                  
        case '1':
          pwm.setPWM(1, 0, 250);
          delay(100);
          pwm.setPWM(3, 0, 245);
          delay(100);
          //pwm.setPWM(5, 0, 400);
          //delay(100);
          //pwm.setPWM(8, 0, 400);
          digitalWrite(2, LOW);
          digitalWrite(3, HIGH);
          digitalWrite(4, HIGH);
          digitalWrite(5, HIGH);
          digitalWrite(A0, HIGH);
          digitalWrite(A1, HIGH);
          digitalWrite(A2, HIGH);
          digitalWrite(A3, HIGH);
          break;

        case '2':
          pwm.setPWM(1, 0, 250);
          delay(100);
          pwm.setPWM(3, 0, 290);
          delay(100);
          //pwm.setPWM(5, 0, 400);
          //delay(100);
          //pwm.setPWM(8, 0, 175);
          digitalWrite(2, HIGH);
          digitalWrite(3, LOW);
          digitalWrite(4, HIGH);
          digitalWrite(5, HIGH);
          digitalWrite(A0, HIGH);
          digitalWrite(A1, HIGH);
          digitalWrite(A2, HIGH);
          digitalWrite(A3, HIGH);
          break;        
         
        case '3':
          pwm.setPWM(1, 0, 300);
          delay(100);
          pwm.setPWM(2, 0, 285);
          delay(100);
          pwm.setPWM(4, 0, 310);
          delay(100);
          //pwm.setPWM(7, 0, 400);
          digitalWrite(2, HIGH);
          digitalWrite(3, HIGH);
          digitalWrite(4, LOW);
          digitalWrite(5, HIGH);
          digitalWrite(A0, HIGH);
          digitalWrite(A1, HIGH);
          digitalWrite(A2, HIGH);
          digitalWrite(A3, HIGH);
          break; 
                
        case '4':
          pwm.setPWM(1, 0, 300);
          delay(100);
          pwm.setPWM(2, 0, 290);
          delay(100);
          pwm.setPWM(4, 0, 370);
          delay(100);
          //pwm.setPWM(7, 0, 175);
          digitalWrite(2, HIGH);
          digitalWrite(3, HIGH);
          digitalWrite(4, HIGH);
          digitalWrite(5, LOW);
          digitalWrite(A0, HIGH);
          digitalWrite(A1, HIGH);
          digitalWrite(A2, HIGH);
          digitalWrite(A3, HIGH);
          break; 
                
        case '5':
          pwm.setPWM(1, 0, 300);
          delay(100);
          pwm.setPWM(2, 0, 350);
          delay(100);
          pwm.setPWM(5, 0, 210);
          delay(100);
          pwm.setPWM(6, 0, 320);
          digitalWrite(2, HIGH);
          digitalWrite(3, HIGH);
          digitalWrite(4, HIGH);
          digitalWrite(5, HIGH);
          digitalWrite(A0, LOW);
          digitalWrite(A1, HIGH);
          digitalWrite(A2, HIGH);
          digitalWrite(A3, HIGH);
          break;  
               
        case '6':
          pwm.setPWM(1, 0, 300);
          delay(100);
          pwm.setPWM(2, 0, 350);
          delay(100);
          pwm.setPWM(5, 0, 210);
          delay(100);
          pwm.setPWM(6, 0, 275);
          digitalWrite(2, HIGH);
          digitalWrite(3, HIGH);
          digitalWrite(4, HIGH);
          digitalWrite(5, HIGH);
          digitalWrite(A0, HIGH);
          digitalWrite(A1, LOW);
          digitalWrite(A2, HIGH);
          digitalWrite(A3, HIGH);
          break;   

        case '7':
          pwm.setPWM(1, 0, 300);
          delay(100);
          pwm.setPWM(2, 0, 350);
          delay(100);
          pwm.setPWM(5, 0, 270);
          delay(100);
          pwm.setPWM(7, 0, 240);
          //delay(100);
          digitalWrite(2, HIGH);
          digitalWrite(3, HIGH);
          digitalWrite(4, HIGH);
          digitalWrite(5, HIGH);
          digitalWrite(A0, HIGH);
          digitalWrite(A1, HIGH);
          digitalWrite(A2, LOW);
          digitalWrite(A3, HIGH);
          break;  
               
        case '8':
          pwm.setPWM(1, 0, 300);
          delay(100);
          pwm.setPWM(2, 0, 350);
          delay(100);          
          pwm.setPWM(5, 0, 270);
          delay(100);
          pwm.setPWM(7, 0, 330);
          digitalWrite(2, HIGH);
          digitalWrite(3, HIGH);
          digitalWrite(4, HIGH);
          digitalWrite(5, HIGH);
          digitalWrite(A0, HIGH);
          digitalWrite(A1, HIGH);
          digitalWrite(A2, HIGH);
          digitalWrite(A3, LOW);
          break;   
              
     
     
  }   
    
}

If you want to read multiple key presses, you might want to use

keypad.getKey();

more than once. The easiest method would be to always read 2 keys and require '01' for 1, '02' for 2, etc.

Give it a try and if you get stuck, ask for more help

The other way is to designate one of the non-digit keys to mean "use the value that you have calculated based on the key presses so far, and reset the value to 0", like an enter key would usually do.

PaulS:
The other way is to designate one of the non-digit keys to mean "use the value that you have calculated based on the key presses so far, and reset the value to 0", like an enter key would usually do.

Thay's exactly what I was wanting to do. Use * as enter after number input but I have no idea how to write the code. Would you please give me an example of code to help me along?

PRH3

here is an [untested] function that will do that:

int getNumericKeypadValue() {
  byte key;
  int value = 0;
  const int maxKeys = 3;    // allow 000-999
  int keyCount = 0;
  
  while( 1 ) {
    key = keypad.getKey();
    if ( key == '*' ) {
      // we are done, return
      return value;
    }
    if ( key == '#' ) {
      // ignore pound key
    } else {
      // we have a char '0' - '9'
      // convert to digit and add it into our value
      // unless we have already read in maxKeys
      if ( keyCount < maxKeys ) {
        value = value * 10 + key - '0';
        keyCount++;
      }
    }
  }
}

You will want to call this function in your loop() rather than getKey() and use the return value to figure out what you want to do. You will also have to modify your case statements since the value returned is now an integer, not a single char (case 1 vs. case '1')

Thank you so much blh64. I will try to work this into the code and try it.

Many, many thanks again.

blh64:
here is an [untested] function that will do that:

You will want to call this function in your loop() rather than getKey() and use the return value to figure out what you want to do. You will also have to modify your case statements since the value returned is now an integer, not a single char (case 1 vs. case '1')

What is the point, since you don't use an array to store the entered characters, in limiting the size of the entered value? Obviously, it doesn't make sense to allow entering 1641681684483846 when the type is int. On the other hand, there is no reason to limit the value to a3 digit number.

PaulS:
What is the point, since you don't use an array to store the entered characters, in limiting the size of the entered value? Obviously, it doesn't make sense to allow entering 1641681684483846 when the type is int. On the other hand, there is no reason to limit the value to a3 digit number.

The OP wanted a two digit code, nothing more. I merely pointed out how you could limit it. Maybe it makes sense to allow only a certain number of digits. If you don't, you have the potential of overflowing your int.

blh64:
The OP wanted a two digit code, nothing more. I merely pointed out how you could limit it.

I missed that.

I am still having trouble getting my sketch to accept multiple keypad presses of numbers greater than
0-9.
I want to be able to use it to trigger more than 10 case commands from 0 to 99. I inserted some things that someone told me may work but am not having much luck. I will be using the * key to end keypad entry. The following is my total sketch and the beginning of the loop is looping twice whenever I press the * key and not accepting digit entries from the keypad. Please help! The first code box contains the loop section of my sketch that works perfectly for 0-9 cases. The second has the suggested elements for double digits that does not work.

void loop()
{
  char key = keypad.getKey();  //Press a keypad key
        
    if (key){
    Serial.println(key);
         
    switch(key){  //switch-case looks for numerals 1-9, other are ignored               
                  //the selected case positions switches with pwm.set
                  //and then the required relay will be tripped to power a single track
                   
        case '1':
/*Relay-St Louis Staging Yard
  Sets switches to selected track
  Turns on a relay in a cascade configuration.

  modified Jan 2, 2017
  by Carl Schoeneberg 
  
  modified Sept 23, 2018
  by Paul R. Hayden  - to enable use of up to 2 key stokes than '*' for enter
*/
//Libraries and required code
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
#include <Keypad.h>

const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] =
  {{'1','2','3'},
   {'4','5','6'},
   {'7','8','9'},
   {'*','0','#'}};
byte rowPins[ROWS] = {2,3,4,5};
byte colPins[COLS] = {6,7,8};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

//end of required code

// the setup function runs once when you press reset or power the board

void setup() 
{
  Serial.begin (9600);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(A0, OUTPUT);
  pinMode(A1, OUTPUT);
  pinMode(A2, OUTPUT);
  pinMode(A3, OUTPUT);
  pwm.begin();  
  pwm.setPWMFreq(60);
  Serial.begin(9600);
  Serial.println("16 channel Servo Test");
  //yield();
  //int S1S = 250;
  //int S1L = 300;
  pwm.setPWM(1, 0, 250);
  delay(100);
  pwm.setPWM(3, 0, 245);
  delay(100);
  //pwm.setPWM(5, 0, 400);
  //delay(100);
  //pwm.setPWM(8, 0, 400);
  digitalWrite(9, LOW);
  digitalWrite(10, HIGH);
  digitalWrite(11, HIGH);
  digitalWrite(12, HIGH);
  digitalWrite(A0, HIGH);
  digitalWrite(A1, HIGH);
  digitalWrite(A2, HIGH);
  digitalWrite(A3, HIGH);
}

// the loop function runs over and over again forever

void loop()
{
//You will want to call this function in your loop() rather than getKey() and 
//use the return value to figure out what you want to do.  You will also have 
//to  modify your case statements since the value returned is now an 
//integer, not a single char (case 1 vs. case '1')

  int getNumericKeypadValue();
  byte key;
  int value = 0;
  const int maxKeys = 2;    // allow 00-99
  int keyCount = 0;
  
  while( 1 ) {
    key = keypad.getKey();
    if ( key == '*' ) {
      // we are done, return
      return value;
      Serial.print(value);
    }
    if ( key == '#' ) {
      // ignore pound key
    } else {
      // we have a char '0' - '9'
      // convert to digit and add it into our value
      // unless we have already read in maxKeys
      if ( keyCount < maxKeys ) {
        value = value * 10 + key - '0';
        keyCount++;
     Serial.println("Here");   
     
    switch(key)  //switch-case looks for numerals 1-9, other are ignored
    {             
                  //the selected case positions switches with pwm.set
                  //and then the required relay will be tripped to power a single track
                  
        case 1:
          pwm.setPWM(1, 0, 250);
          delay(100);
          pwm.setPWM(3, 0, 245);
          delay(100);
          //pwm.setPWM(5, 0, 400);
          //delay(100);
          //pwm.setPWM(8, 0, 400);
          digitalWrite(9, LOW);
          digitalWrite(10, HIGH);
          digitalWrite(11, HIGH);
          digitalWrite(12, HIGH);
          digitalWrite(A0, HIGH);
          digitalWrite(A1, HIGH);
          digitalWrite(A2, HIGH);
          digitalWrite(A3, HIGH);
          break;

        case 2:
          pwm.setPWM(1, 0, 250);
          delay(100);
          pwm.setPWM(3, 0, 290);
          delay(100);
          //pwm.setPWM(5, 0, 400);
          //delay(100);
          //pwm.setPWM(8, 0, 175);
          digitalWrite(9, HIGH);
          digitalWrite(10, LOW);
          digitalWrite(11, HIGH);
          digitalWrite(12, HIGH);
          digitalWrite(A0, HIGH);
          digitalWrite(A1, HIGH);
          digitalWrite(A2, HIGH);
          digitalWrite(A3, HIGH);
          break;        
         
        case 3:
          pwm.setPWM(1, 0, 300);
          delay(100);
          pwm.setPWM(2, 0, 285);
          delay(100);
          pwm.setPWM(4, 0, 310);
          delay(100);
          //pwm.setPWM(7, 0, 400);
          digitalWrite(9, HIGH);
          digitalWrite(10, HIGH);
          digitalWrite(11, LOW);
          digitalWrite(12, HIGH);
          digitalWrite(A0, HIGH);
          digitalWrite(A1, HIGH);
          digitalWrite(A2, HIGH);
          digitalWrite(A3, HIGH);
          break; 
                
        case 4:
          pwm.setPWM(1, 0, 300);
          delay(100);
          pwm.setPWM(2, 0, 290);
          delay(100);
          pwm.setPWM(4, 0, 370);
          delay(100);
          //pwm.setPWM(7, 0, 175);
          digitalWrite(9, HIGH);
          digitalWrite(10, HIGH);
          digitalWrite(11, HIGH);
          digitalWrite(12, LOW);
          digitalWrite(A0, HIGH);
          digitalWrite(A1, HIGH);
          digitalWrite(A2, HIGH);
          digitalWrite(A3, HIGH);
          break; 
                
        case 5:
          pwm.setPWM(1, 0, 300);
          delay(100);
          pwm.setPWM(2, 0, 350);
          delay(100);
          pwm.setPWM(5, 0, 210);
          delay(100);
          pwm.setPWM(6, 0, 320);
          digitalWrite(9, HIGH);
          digitalWrite(10, HIGH);
          digitalWrite(11, HIGH);
          digitalWrite(12, HIGH);
          digitalWrite(A0, LOW);
          digitalWrite(A1, HIGH);
          digitalWrite(A2, HIGH);
          digitalWrite(A3, HIGH);
          break;  
               
        case 6:
          pwm.setPWM(1, 0, 300);
          delay(100);
          pwm.setPWM(2, 0, 350);
          delay(100);
          pwm.setPWM(5, 0, 210);
          delay(100);
          pwm.setPWM(6, 0, 275);
          digitalWrite(9, HIGH);
          digitalWrite(10, HIGH);
          digitalWrite(11, HIGH);
          digitalWrite(12, HIGH);
          digitalWrite(A0, HIGH);
          digitalWrite(A1, LOW);
          digitalWrite(A2, HIGH);
          digitalWrite(A3, HIGH);
          break;   

        case 27:
          pwm.setPWM(1, 0, 300);
          delay(100);
          pwm.setPWM(2, 0, 350);
          delay(100);
          pwm.setPWM(5, 0, 270);
          delay(100);
          pwm.setPWM(7, 0, 240);
          //delay(100);
          digitalWrite(9, HIGH);
          digitalWrite(10, HIGH);
          digitalWrite(11, HIGH);
          digitalWrite(12, HIGH);
          digitalWrite(A0, HIGH);
          digitalWrite(A1, HIGH);
          digitalWrite(A2, LOW);
          digitalWrite(A3, HIGH);
          break;  
               
        case 28:
          pwm.setPWM(1, 0, 300);
          delay(100);
          pwm.setPWM(2, 0, 350);
          delay(100);          
          pwm.setPWM(5, 0, 270);
          delay(100);
          pwm.setPWM(7, 0, 330);
          digitalWrite(9, HIGH);
          digitalWrite(10, HIGH);
          digitalWrite(11, HIGH);
          digitalWrite(12, HIGH);
          digitalWrite(A0, HIGH);
          digitalWrite(A1, HIGH);
          digitalWrite(A2, HIGH);
          digitalWrite(A3, LOW);
          break;   
              
     
     
     
    
          
        }
      }
    }
  }
}
  int getNumericKeypadValue();
  byte key;
  int value = 0;
  const int maxKeys = 2;    // allow 00-99
  int keyCount = 0;
  
  while( 1 ) {
    key = keypad.getKey();
    if ( key == '*' ) {
      // we are done, return
      return value;
      Serial.print(value);
    }
    if ( key == '#' ) {
      // ignore pound key
    } else {
      // we have a char '0' - '9'
      // convert to digit and add it into our value
      // unless we have already read in maxKeys
      if ( keyCount < maxKeys ) {
        value = value * 10 + key - '0';
        keyCount++;
     Serial.println("Here");

This looks like it's intended as a function definition except it's in the middle of the loop() function and has a ; after the initial definition so it does nothing. What looks like it's code is missing braces {} so it's not in the function, instead it's inline in loop() where it doesn't belong.

I don't think you understood the "things that someone told you" very well. Could you perhaps go back and ask "someone" what they really meant?

Steve

Add a case for the NO_KEY value (0). Right now you are multiplying your value by 10 and subtracting '0' every time nobody presses a button. :frowning:

You are also acting on 'value' whenever someone types a key. How can you get to '10' when you act on '1'. Don't precess 'value' until someone presses '*'.

And 'value' is neither 'static' or global so it gets cleared each time you enter loop().

/*Relay-St Louis Staging Yard
  Sets switches to selected track
  Turns on a relay in a cascade configuration.


  modified Jan 2, 2017
  by Carl Schoeneberg


  modified Sept 23, 2018
  by Paul R. Hayden  - to enable use of up to 2 key stokes than '*' for enter
*/
//Libraries and required code
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
#include <Keypad.h>


const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] =
{
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};
byte rowPins[ROWS] = {2, 3, 4, 5};
byte colPins[COLS] = {6, 7, 8};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );


//end of required code


// the setup function runs once when you press reset or power the board


void setup()
{
  Serial.begin (9600);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(A0, OUTPUT);
  pinMode(A1, OUTPUT);
  pinMode(A2, OUTPUT);
  pinMode(A3, OUTPUT);
  pwm.begin();
  pwm.setPWMFreq(60);
  Serial.begin(9600);
  Serial.println("16 channel Servo Test");
  //yield();
  //int S1S = 250;
  //int S1L = 300;
  pwm.setPWM(1, 0, 250);
  delay(100);
  pwm.setPWM(3, 0, 245);
  delay(100);
  //pwm.setPWM(5, 0, 400);
  //delay(100);
  //pwm.setPWM(8, 0, 400);
  digitalWrite(9, LOW);
  digitalWrite(10, HIGH);
  digitalWrite(11, HIGH);
  digitalWrite(12, HIGH);
  digitalWrite(A0, HIGH);
  digitalWrite(A1, HIGH);
  digitalWrite(A2, HIGH);
  digitalWrite(A3, HIGH);
}


// the loop function runs over and over again forever


void loop()
{
  //You will want to call this function in your loop() rather than getKey() and
  //use the return value to figure out what you want to do.  You will also have
  //to  modify your case statements since the value returned is now an
  //integer, not a single char (case 1 vs. case '1')


  byte key;
  static int value = 0;
  const int maxKeys = 2;    // allow 00-99
  static int keyCount = 0;


  key = keypad.getKey();
  if (key == NO_KEY)
  {
  }
  else if ( key == '*' )
  {
    if (keyCount == 0)
      return;  // Ignore '*' of no digits were entered
    Serial.print(value);
    int input = value;
    value = 0;
    keyCount = 0;
    switch (input) //switch-case looks for numerals 1-9, other are ignored
    {
      //the selected case positions switches with pwm.set
      //and then the required relay will be tripped to power a single track


      case 1:
        pwm.setPWM(1, 0, 250);
        delay(100);
        pwm.setPWM(3, 0, 245);
        delay(100);
        //pwm.setPWM(5, 0, 400);
        //delay(100);
        //pwm.setPWM(8, 0, 400);
        digitalWrite(9, LOW);
        digitalWrite(10, HIGH);
        digitalWrite(11, HIGH);
        digitalWrite(12, HIGH);
        digitalWrite(A0, HIGH);
        digitalWrite(A1, HIGH);
        digitalWrite(A2, HIGH);
        digitalWrite(A3, HIGH);
        break;


      case 2:
        pwm.setPWM(1, 0, 250);
        delay(100);
        pwm.setPWM(3, 0, 290);
        delay(100);
        //pwm.setPWM(5, 0, 400);
        //delay(100);
        //pwm.setPWM(8, 0, 175);
        digitalWrite(9, HIGH);
        digitalWrite(10, LOW);
        digitalWrite(11, HIGH);
        digitalWrite(12, HIGH);
        digitalWrite(A0, HIGH);
        digitalWrite(A1, HIGH);
        digitalWrite(A2, HIGH);
        digitalWrite(A3, HIGH);
        break;


      case 3:
        pwm.setPWM(1, 0, 300);
        delay(100);
        pwm.setPWM(2, 0, 285);
        delay(100);
        pwm.setPWM(4, 0, 310);
        delay(100);
        //pwm.setPWM(7, 0, 400);
        digitalWrite(9, HIGH);
        digitalWrite(10, HIGH);
        digitalWrite(11, LOW);
        digitalWrite(12, HIGH);
        digitalWrite(A0, HIGH);
        digitalWrite(A1, HIGH);
        digitalWrite(A2, HIGH);
        digitalWrite(A3, HIGH);
        break;


      case 4:
        pwm.setPWM(1, 0, 300);
        delay(100);
        pwm.setPWM(2, 0, 290);
        delay(100);
        pwm.setPWM(4, 0, 370);
        delay(100);
        //pwm.setPWM(7, 0, 175);
        digitalWrite(9, HIGH);
        digitalWrite(10, HIGH);
        digitalWrite(11, HIGH);
        digitalWrite(12, LOW);
        digitalWrite(A0, HIGH);
        digitalWrite(A1, HIGH);
        digitalWrite(A2, HIGH);
        digitalWrite(A3, HIGH);
        break;


      case 5:
        pwm.setPWM(1, 0, 300);
        delay(100);
        pwm.setPWM(2, 0, 350);
        delay(100);
        pwm.setPWM(5, 0, 210);
        delay(100);
        pwm.setPWM(6, 0, 320);
        digitalWrite(9, HIGH);
        digitalWrite(10, HIGH);
        digitalWrite(11, HIGH);
        digitalWrite(12, HIGH);
        digitalWrite(A0, LOW);
        digitalWrite(A1, HIGH);
        digitalWrite(A2, HIGH);
        digitalWrite(A3, HIGH);
        break;


      case 6:
        pwm.setPWM(1, 0, 300);
        delay(100);
        pwm.setPWM(2, 0, 350);
        delay(100);
        pwm.setPWM(5, 0, 210);
        delay(100);
        pwm.setPWM(6, 0, 275);
        digitalWrite(9, HIGH);
        digitalWrite(10, HIGH);
        digitalWrite(11, HIGH);
        digitalWrite(12, HIGH);
        digitalWrite(A0, HIGH);
        digitalWrite(A1, LOW);
        digitalWrite(A2, HIGH);
        digitalWrite(A3, HIGH);
        break;


      case 27:
        pwm.setPWM(1, 0, 300);
        delay(100);
        pwm.setPWM(2, 0, 350);
        delay(100);
        pwm.setPWM(5, 0, 270);
        delay(100);
        pwm.setPWM(7, 0, 240);
        //delay(100);
        digitalWrite(9, HIGH);
        digitalWrite(10, HIGH);
        digitalWrite(11, HIGH);
        digitalWrite(12, HIGH);
        digitalWrite(A0, HIGH);
        digitalWrite(A1, HIGH);
        digitalWrite(A2, LOW);
        digitalWrite(A3, HIGH);
        break;


      case 28:
        pwm.setPWM(1, 0, 300);
        delay(100);
        pwm.setPWM(2, 0, 350);
        delay(100);
        pwm.setPWM(5, 0, 270);
        delay(100);
        pwm.setPWM(7, 0, 330);
        digitalWrite(9, HIGH);
        digitalWrite(10, HIGH);
        digitalWrite(11, HIGH);
        digitalWrite(12, HIGH);
        digitalWrite(A0, HIGH);
        digitalWrite(A1, HIGH);
        digitalWrite(A2, HIGH);
        digitalWrite(A3, LOW);
        break;




    }
  }
  else if ( key == '#' )
  {
    // ignore pound key
  }
  else
  {
    // we have a char '0' - '9'
    // convert to digit and add it into our value
    // unless we have already read in maxKeys
    if ( keyCount < maxKeys )
    {
      value = value * 10 + (key - '0');
      keyCount++;
      Serial.println("Here");
    }
  }
}

Is there anyone of you that are telling me what the code is not doing that can write a paragraph of code that solves the problem? I am a model railroader trying to get something to work for my hobby. I am 64 years old and by the time I could figure this out I'll be dead. Give an old man a break and show me the correct way to get this to work, please. I am at your mercy!

Paul R.

I already put the required changes in the sketch in my previous reply. Give it a try. Click on the [Select] link at the top of the Code:, and do a Copy and Paste to put it into a new sketch. I’d be happy to help further. Us young folks (I’m only 62) should honor our elders. :slight_smile:

John,

It works like a champ. Thank you so much for your help

Paul