Entering 3 digits

The getKey() method is NOT a blocking function. Most of the time when it is called, no key is being pressed, so the return value is NO_KEY. You need to add another if statement after the call to getKey():

  char key = keypad.getKey();
  if(key != NO_KEY) // Do nothing is no key is pressed
  {
    if (key != '*')
    {
       keyIn += key;
    }
    else
    {
       // The else stuff
    }
  }

Ok this should work with the added NO_KEY condition

//these two need to go at the top of the screen
int currentCommand = 0;
char Data[2];



void loop(){
if(key != NO_KEY) // Do nothing if no key is pressed, incorporated from PaulS's example.
  {
  char key = keypad.getKey();
  
  if (key != '*'){
    Data[currentCommand++] = key;
}

else {
    int keyIn = atoi(Data);
    lcd.begin(16,0);
    lcd.setCursor(6,0);
    lcd.print(keyIn);     
    lcd.print("  ");
    Serial.println(keyIn);
    while(currentCommand !=0){   // This can be used for any array size, 
    Data[currentCommand--] = 0; //clear for new data
        }
     } 
  }
}

Ok this should work with the added NO_KEY condition

Did you even try compiling this?

if(key != NO_KEY) // Do nothing if no key is pressed, incorporated from PaulS's example.
  {
  char key = keypad.getKey();
  
  if (key != '*'){
    Data[currentCommand++] = key;
}

You can't test a variable before you have valued it, or even declared it.

what is not declaired? oh I see, I put the char key = keypad.getKey(); inside the if statement. Yea I didn't compile it, I dont have my laptop with me today, but im sure he would have caught and fixed it himself.

@dcr_inc

change it to this:

char key = keypad.getKey(); // put it above the nokey if statement.

if(key != NO_KEY) // Do nothing if no key is pressed, incorporated from PaulS's example.
  {  
  if (key != '*'){
    Data[currentCommand++] = key;
}

Thanks again for all of your help...

I will upload this code and see if I can make it do what I need..

I only wish I could get the hang of this language... I can do ladder logic but cant seem to grasp this..

Thanks again

i understand your problem dcr_inc. i am also well verse in PLC programming.

I can do ladder logic

Climb a ladder. It wobbles and tilts. Where's the logic in that?

actually dcr_inc after almost a half a year of trying to study arduino and how to relate it back to PLC, i think had found the solution,
I am now able to make all the basic input ,output, keep, delay on, counter with arduino as we could use in PLC.
I have also just recently discovered that a State diagram and Timing diagram could be easily implemented in arduino
other then that, Shift function in PLC can also be use in arduino

this however is slightly different that just using the ladder diagram,it use words but hay I'm trying to make function that we(PLC programmer) could use to help use the same logic use in PLC to be use in arduino.

@PaulS...
There isn't any !!!!! LOL...

For my project, I really want to use the Arduino instead of the PLC.. But this language is a real bear for me to grasp.. Almost wish there were someone who wrote this stuff for a few bucks and a beer !!!LOL..

Its simple... enter 3 or 4 digits via keypad.. Push "*" to enter... Display the digits on LCD #1...Have Arduino energize a relay (Pin goes High)... Have rotary encoder input pulses... count pulses as they come in...Display the count on LCD #2... Have Arduino take pin Low when inputted digits match the rotary encoders count... Have a button to clear the rotary encoder count (stack) and the "#" key as a backspace or delete key for the numeric input from the keypad...

Is this a complicated sketch?.. Is it lengthly?

So far I have the keypad talking to the Arduino and the Keyed in digits sort of displaying on the LCD# 1... The rotary encoder is inputting the count but not working correctly.. Lots of bounce..

Hair is getting thinner by the evening with this project..

I appreciate all of the suggestions and help this community has provided.. I'm sure I will require ALOT more help before I'm done...

Almost wish there were someone who wrote this stuff for a few bucks and a beer !!!LOL..

There are, if the beer is good and cold. The problem is that you are the only one with the hardware.

Ok, does the keypad finally work?
You have an encoder to input pulses, incrementally.
If the keypad data matches the encoder data, it triggers a relay.

What exactly are you making that would require 2 LCD screens, a rotary encoder and a keypad?

I'm just curious, that's all.

HazardsMind... Its for a LARGE tubing bender in a private residence.. He is building a Mud truck and wants to bend a lot of tubing..

Its my brother so I'm attempting to help him out..

Sequence.. Figure out what angle he wants.. look on table, retrieve the two or three digit #( count from encoder, predetermined), enter the digits via the keypad, have digits appear on LCD#1 (for reference and verification), push the reset/clear key (separate push button,this clears the encoder count stack, resets to 0), Push the * key, This sets the first counter stack to digits entered via keypad, output pin goes high(relay attached to output pin to control motor), Rotary encoder is attached to the arm and outputs pulses as the arm moves (Pipe Bends), the count is displayed on LCD#2 to show the bend value... when the rotary encoder count matches the keypad # the output pin goes low and everything stops..

@PaulS.. As for the beer and hardware, Where do I send it to??..LOL (i'm serious.. I have two sets of hardware if your serious)

Send me a PM. I'll provide an address. I have time off after Christmas.

HazardsMind.... yes the code works.. No more overflow..Ok.. Is there a way to show the digits on the display Before pushing the * key?.. I know I'm a pain in the Arse..

Is there a way to show the digits on the display Before pushing the * key?.

Yes. It's exactly the same as displaying them after the * key is pressed.

Your not a pain in the arse, your like everyone else.You try really hard (on your own) for something to work, and when it doesn't you turn for help. Now what we do, is try to cross everything off the "to do list" before tackling another problem, that way we know that everything prior works. So I was basically crossing the keypad off.

Now as for displaying what you enter, that is relativly simple, but you will need to tweak the code a bit.

I can tell you what to put and where to put it, or I can take a crack at it myself, but again I dont know if it will work without any actual hardware to confirm that it does so. So I would rather you wrote it yourself and test it.

=========================================
In a nut shell what you want to see is this, if a number gets pressed, it shows on the LCD. If another number is pressed ,the cursor moves over and outputs the next number, same for the third number. Now with this, you can add the backspace if you want.

What you need to do is add the following under "Data[currentCommand++] = key;" in the IF statement //sorry, had to make an edit

lcd.setCursor(6 + currentCommand,0); // you need to insert "currentCommand" to move the cursor over for the next number.
lcd.print(Data[currentCommand]);//then print it. Im not sure if this will output garbage, if it does let me know.

It would be a good idea to make a new sketch, copy/paste the working code and test THIS code out with it, rather than modify the one you have now. Reason why is because if this new code dont work, then you have the original code to try again.

Try this as a start.

NOTE, this is compiled, but not tested

I added the code as supplied.. The digits as entered are displayed as ---- (actually three horizontal lines in a stack) when inputted... When you push * it removes the dashes and displays the digits you hit..

The full code is included here:

/* @file HelloKeypad.pde
|| @version 1.0
|| @author Alexander Brevig
|| @contact alexanderbrevig@gmail.com
||
|| @description
|| | Demonstrates the simplest use of the matrix Keypad library.
|| #
*/
#include <Keypad.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
String keyIn;
int currentCommand = 0;

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

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

void setup(){
Serial.begin(9600);
lcd.begin(15,2);
}

void loop(){
//lcd.begin(15,2);
lcd.setCursor(2,0);
lcd.print("Input Digits");

char key = keypad.getKey();
if(key != NO_KEY) // Do nothing if no key is pressed, incorporated from PaulS's example.
{
if (key != '*') {
Data[currentCommand++] = key;
lcd.setCursor(6 + currentCommand,1);
lcd.print(Data[currentCommand]);

}

else {
int keyIn = atoi(Data);
lcd.setCursor(6,1);
lcd.print(keyIn);
lcd.print(" ");
Serial.println(keyIn);
while(currentCommand !=0){ // This can be used for any array size,
Data[currentCommand--] = 0; //clear for new data
}
}
}
}

I'm / We're gettin there !!

KEYPAD_TEST_as_entered.ino (1.41 KB)

Quick question, why is keyIn declaired as a string at the top, but an int at the bottom? Make the one at the top the "int", and remove just "int" at the bottom.
also char Data[5]; should only be 2, not 5. umm, const byte COLS = 4; //should go back to 3, unless you plan on getting a 4x4 keypad, in which case you need to fix the numbers in char keys[ROWS][COLS]. You have a 15 by 2 LCD, I thought you had a 16 by 2 ?

ok, so you got "----" as the output when you entered the numbers but it was correct when you pressed " * ", weird. Ok try this,

void loop(){
  //lcd.begin(15,2);
  lcd.setCursor(2,0);
  lcd.print("Input Digits");

  char key = keypad.getKey();
if(key != NO_KEY) // Do nothing if no key is pressed, incorporated from PaulS's example.
  {
      if (key != '*') {
    Data[currentCommand++] = key;
    keyIn = atoi(Data);
    lcd.setCursor(6,1);
    lcd.print(keyIn);    //this should print the first digit in it's same spot and the 2nd and 3rd will follow like normal, when inputted.   
}

else {
     //keyIn = atoi(Data);
    //lcd.setCursor(6,1);
    //lcd.print(keyIn);
    //lcd.print("     ");      
    lcd.print(" OK");        //just to tell you * was pressed
    Serial.println(keyIn);
    while(currentCommand !=0){   // This can be used for any array size, 
    Data[currentCommand--] = 0; //clear for new data
        }
     } 
  }
}

Could you post a picture or little video of what your getting on the display?

PaulS.. It's on the way...
HazardsMind...The code is what I grabbed for a publication and I have tweaked it with your and PaulS's help..

I will attempt to get a screen shot for u..
Dave