Go Down

Topic: Entering 3 digits (Read 3733 times) previous topic - next topic

dcr_inc

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
I'm Lost !! At least on the Arduino...

dcr_inc

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

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

HazardsMind

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.
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

dcr_inc

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
I'm Lost !! At least on the Arduino...

HazardsMind

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.
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

dcr_inc

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
I'm Lost !! At least on the Arduino...

HazardsMind

#21
Dec 14, 2012, 04:47 am Last Edit: Dec 14, 2012, 11:55 am by HazardsMind Reason: 1
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: [Select]
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.
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

PaulS

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

HazardsMind

#23
Dec 14, 2012, 02:10 pm Last Edit: Dec 14, 2012, 03:19 pm by HazardsMind Reason: 1
Ok this should work with the added NO_KEY condition

Code: [Select]


//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
        }
     }
  }
}
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

PaulS

Quote
Ok this should work with the added NO_KEY condition

Did you even try compiling this?
Code: [Select]
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.

HazardsMind

#25
Dec 14, 2012, 05:46 pm Last Edit: Dec 14, 2012, 05:53 pm by HazardsMind Reason: 1
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: [Select]

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;
}
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

dcr_inc

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'm Lost !! At least on the Arduino...

ash901226

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

PaulS

Quote
I can do ladder logic

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

ash901226

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.

Go Up