Pages: 1 [2] 3   Go Down
Author Topic: Entering 3 digits  (Read 3203 times)
0 Members and 1 Guest are viewing this topic.
Delta, PA USA
Offline Offline
Newbie
*
Karma: 0
Posts: 30
I'm Lost !!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Folks... I APPRECIATE ALL OF THE INPUT... I am totally at a loss so please accept my appreciation for your knowledge..

Is there any tutorials for what I am trying to do?. I can say I have looked but with no success
Logged

I'm Lost !! At least on the Arduino...

Delta, PA USA
Offline Offline
Newbie
*
Karma: 0
Posts: 30
I'm Lost !!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

In layman's terms, what is this doing?
if (key != '*'){
keyIn += key;

Logged

I'm Lost !! At least on the Arduino...

Queens, New York
Offline Offline
Faraday Member
**
Karma: 98
Posts: 3576
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If key does not see * then it is going to keep adding the pressed digits to the string, and when it does see * then it puts out the data.
Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Delta, PA USA
Offline Offline
Newbie
*
Karma: 0
Posts: 30
I'm Lost !!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok..I learned something today... THANKS..
for some reason I can not get any digits to appear except when the * is pushed I get a 0 on the LCD
Logged

I'm Lost !! At least on the Arduino...

Queens, New York
Offline Offline
Faraday Member
**
Karma: 98
Posts: 3576
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think the reason you get 0 on the LCD is because of the NoKey function, I think it is constantly filling and overfilling the string with zeros, when nothing is pressed.

I could be wrong.
Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Delta, PA USA
Offline Offline
Newbie
*
Karma: 0
Posts: 30
I'm Lost !!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

HazardsMind... For what it's worth... When I look on the term, I see about 30 seconds worth of 0's then random characters.. all this time, the TX LED is lit on the Mega
Logged

I'm Lost !! At least on the Arduino...

Queens, New York
Offline Offline
Faraday Member
**
Karma: 98
Posts: 3576
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here this is what I tried to do, it does not have anything to do with KEYPAD, but it may give you a little push.
Code:
int currentCommand = 0;
char Data[256];

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

void loop() {
  if( Serial.available())       // if data is available to read
  {
    char c= Serial.read();
    if (c == '.'){
     
        long i=atol(Data);
        Serial.println(i);
        Serial.println(currentCommand);
        while(currentCommand !=0){
        Data[currentCommand--] = 0;
        }
      }
    else {   
      Data[currentCommand++] = c;
    }
  }
}


Im still trying to figure out the Keypad code, myself.
« Last Edit: December 14, 2012, 05:55:34 am by HazardsMind » Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 611
Posts: 49092
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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():
Code:
  char key = keypad.getKey();
  if(key != NO_KEY) // Do nothing is no key is pressed
  {
    if (key != '*')
    {
       keyIn += key;
    }
    else
    {
       // The else stuff
    }
  }
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 98
Posts: 3576
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok this should work with the added NO_KEY condition

Code:

//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
        }
     }
  }
}
« Last Edit: December 14, 2012, 09:19:06 am by HazardsMind » Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 611
Posts: 49092
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Ok this should work with the added NO_KEY condition
Did you even try compiling this?
Code:
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.
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 98
Posts: 3576
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
Code:
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;
}
« Last Edit: December 14, 2012, 11:53:24 am by HazardsMind » Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Delta, PA USA
Offline Offline
Newbie
*
Karma: 0
Posts: 30
I'm Lost !!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

I'm Lost !! At least on the Arduino...

Malaysia
Offline Offline
Sr. Member
****
Karma: 7
Posts: 393
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 611
Posts: 49092
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I can do ladder logic
Climb a ladder. It wobbles and tilts. Where's the logic in that?
Logged

Malaysia
Offline Offline
Sr. Member
****
Karma: 7
Posts: 393
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: 1 [2] 3   Go Up
Jump to: