Go Down

Topic: Store Multiple Digit Input from Keypad (Read 2 times) previous topic - next topic

Jewel

Hi!
I have a keypad interfaced with a Arduino Mega.
This is what I want to do:
The user inputs a frequency value (say 100). The number is stored in memory as a variable and then used to output a wave at that frequency (this uses a separate section of codes - I have this part running).
However, I am having issues capturing the input and storing it. As in, if I punch in 1,0,0 it should record as 100; 5,0 as 50 etc. I read through the tutorials and the forum. http://arduino.cc/forum/index.php?topic=57627.0 was helpful in that matter. But I can have a single, double or triple digit input and cannot think of how to code for this.
I hope I was able to explain that well.
I need help with the logic! :) Please guide me!
Thanks!

dxw00d

You need to have either a fixed terminating character, so you enter 5,0,# or 1,0,0,#, or you have to implement a timeout based routine. The fixed terminator is easiest to implement.

Jewel

Oh that seems a good idea! Will try coding and seeing if ti works! Thanx!

Jewel

Hi!

Does this make sense?

/Voltage - Functions to capture input, print on screen and store value//
//Voltage - Digit 1//
int GetVoltage1()
{
    int key = keypad.getKey();
    switch (key)
             {
                 case NO_KEY: break;
                 case '0': case '1': case '2': case '3': case '4':
                         case '5': case '6': case '7': case '8': case '9':
                              {
                                   lcd.print(key);
                                   key = digit1;
                                   break;
                              }
                    case '*':
                         {
                              voltage2();
                              break;
                         }
             }             
   return digit1;
}

//Voltage - Digit 2//
int GetVoltage2()
{
    int key = keypad.getKey();
    switch (key)
             {
                    case NO_KEY: break;
                    case '0': case '1': case '2': case '3': case '4':
                         case '5': case '6': case '7': case '8': case '9':
                              {
                                   lcd.print(key);
                                   key = digit2;
                                   break;
                              }
                    case '*':
                         {
                              voltage2();
                              break;
                         }
             }             
   }
   return digit2;
}

//Voltage - Digit 3//
int GetVoltage3()
{
    int key = keypad.getKey();
    switch (key)
             {
                    case NO_KEY: break;
                    case '0': case '1': case '2': case '3': case '4':
                         case '5': case '6': case '7': case '8': case '9':
                              {
                                   lcd.print(key);
                                   key = digit3;
                                   break;
                              }
                    case '*':
                         {
                              voltage2();
                              break;
                         }
             }             
   }
   return digit3;
}

//Voltage - Calculate Input//
int DutyCycle1 ()
{
    int input;
    input = (100*digit1)+(10*digit2)+(1*digit3);
    input = DutyCycle1;
    return DutyCycle1;
}

156sab

Hi,

    I am new to the arduino world and would like to implyment a similar
method of storing multiple digits from a keypad on a Arduino UNO.

Is the posted code easily adjusted to run it on the UNO and display via
the serial monitor function.

kind regards

shaun

Go Up