Keypad acting like a phone

I have a programming question for the Arduino. We have a keypad that is used to “dial a phone”. We got the numbers working perfectly fine, when you hit 1, it means 1. The problem we’re having is we can’t get it to act like a phone, in the sense that, when you dial 1, and wait like a second or two, it will go and dial that number, but when you hit 1,2 and 3 within that period, it dials 123. Is this possible at all?

#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'#','0','*'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){
  Serial.begin(9600);
}

void loop(){
  char key = keypad.getKey();

  if (key != NO_KEY){
    Serial.println(key);
  }
}

So, I’d change “key” to an array, and have that array of numbers print instead.

So, I'd change "key" to an array, and have that array of numbers print instead.

You can't change key to an array. The getKey() method returns which single key, if any, was pressed.

You can store that single key in an array, and increment the index into the array.

It really isn't clear what you are trying to do.

All you need is to ‘reset’ a time stamp within the key pressed “if”, and outside the if, if the timestamp differs from the actual time by a certain amount, then dial the number.

You can store the numbers you have typed into elements of an array.

majenko:
All you need is to 'reset' a time stamp within the key pressed "if", and outside the if, if the timestamp differs from the actual time by a certain amount, then dial the number.

You can store the numbers you have typed into elements of an array.

Do you have any sort of code example for that? I get what you mean I'm just not 100% sure how to implement it.

The blink without delay example shows how to record when an event occurs, such as pressing a key. It also shows how to take action if a specific amount of time has elapsed.

You could modify that approach to reset the time each time a key is pressed. Then, when no key has been pressed for a while (now minus last time is greater than interval), do something.

You are far better off, though, forgetting about the timing stuff, and have a key, perhaps '*' be the "Do it" key.

PaulS:
The blink without delay example shows how to record when an event occurs, such as pressing a key. It also shows how to take action if a specific amount of time has elapsed.

You could modify that approach to reset the time each time a key is pressed. Then, when no key has been pressed for a while (now minus last time is greater than interval), do something.

You are far better off, though, forgetting about the timing stuff, and have a key, perhaps '*' be the "Do it" key.

As much as I like your "do it" key idea, this is a project intended to be used by very young kids.

As much as I like your "do it" key idea, this is a project intended to be used by very young kids.

Then dialing a number after an interval that would be easy for adults to deal with hardly seems like the best approach to use with young kids. They will expect to make mistakes, and be able to correct them, and to initiate an action when they have entered enough info. At least, I think that will prove to be the case.

On all the phones I've ever used you either press the green handset button and then dial the number, which it then does "live" - sending each digit to the exchange as you press it and when the exchange has enough numbers to make a valid number it connects you through, or you dial the number first, then press the green handset button, and the phone then sends the digits en-masse.

Well, I did actually use one of those land line phones with that funky rotating dial few decades ago. It didn't have a "call" button, that much I can remember...

Chaul:
Well, I did actually use one of those land line phones with that funky rotating dial few decades ago. It didn't have a "call" button, that much I can remember...

Yes it did - it's built into the handset cradle - you lift the handset, it releases the button, initiating the call. The same action as pressing the green handset button before dialing on a modern phone. Again, when the exchange has received enough numbers it just connects.

We've built it into an old pay phone. So to fit that there is no call or send button.