Help getting user input...

Hi everyone,

I was wondering if someone would point me in the right direction in regards to this problem I’m experiencing… basically, I need to get a 2-digit number from the user and put this in a variable someplace…

I’ve got an Arduino UNO connected via I2C to a Byvac BV4618 LCD/Keypad controller… and a 4x4 membrane keypad.

What I can’t figure it out is this…

When the user enters the two-digit reading (01-99), it should then print out “Reading updated to XX”… I can’t get it to work because I’m getting the error about the variable…

I’m also not sure if the digits the user is entering are actually being appended or added to eachother… ie: if a user enters 11 - does the variable then store 11 or 2 (by adding them together)?

If this is not making any sense, please let me know and I’ll clarify as much as possible.

Many thanks in advance,
Armen

The part of my code which is causing me grief is in brown (more like maroon)… and I’m actually getting this error:
( error: no matching function for call to ‘BV4618_I::puts(String&)’ )

if(screen== 9){

lcd.cls();
lcd.puts(“Update Reading?”);
lcd.rowcol(2,1);
lcd.puts(“A~Yes B~No/Cancel”);

//// ASK IF USER WANTS TO CHANGE
int choice;
String input_KA;

for (;;){
choice = lcd.key();

//if A is pressed do following
if(choice== 10){
lcd.cls();
lcd.rowcol(1,1);
lcd.puts(“Enter two-digit reading”);
lcd.rowcol(2,1);
lcd.puts("~");

/// Get user input
while(input_KA.length()<3){
if(!lcd.keyint()) {
int tmp = lcd.key();
tmp+=‘0’;
lcd.putch(tmp);
input_KA += tmp;

}

}
//// Finish geting user input
lcd.puts("Reading updated to ");
lcd.puts.(input_KA);

delay(2000);

break;
choice = 11;
}

//if B is pressed do following
{
if(choice == 11){
lcd.cls();
break;}
}
}

lcd.cls();
}

if(screen== 9){

lcd.cls();
lcd.puts("Update Reading?");
lcd.rowcol(2,1);
lcd.puts("A~Yes  B~No/Cancel");
     
      //// ASK IF USER WANTS TO CHANGE
      int choice;
      String  input_KA;
   
        for (;;){
        choice = lcd.key();
       
            //if A is pressed do following
            if(screen== 10){
            lcd.cls();

If screen is 9, how can it also be 10?

The String class has a toCharArray() method that can extract the embedded character array that the lcd class can print.

On the other hand, since your string is limited to 2 characters, using the String class at all is simply being lazy. Just use a char array.

Paul, thank you for your input, however I don’t appreciate being called lazy. I am a law student not a programmer and have just started with Arduino and programming in general as a hobby. Therefore, the code which I have put together above is a result of many nights of reading and learning various bits from Arduino’s programming reference page and other similar sites on the Internet.

I have not simply posted this question because I haven’t spent time trying to solve the problem myself. I had, on the contrary, hoped to receive some positive guidance.

In regards to the second variable regarding the screen, that was a typo and I have corrected it.

In any case, I have changed the “string” into an array and had my code is now as follows and have read up on arrays and every thing’s fine now.

if(screen == 9){

lcd.cls();
lcd.rowcol(1,1);
lcd.puts("Current KA ");
lcd.puts(disp_KA);
lcd.rowcol(2,1);
lcd.puts(“Update KA Reading?”);
lcd.rowcol(3,1);
lcd.puts(“A~Yes B~No/Cancel”);

//// ASK IF USER WANTS TO CHANGE
int choice;
int input_KA = {0,0};

for (;;){
choice = lcd.key();

//if A is pressed do following
if(choice == 10){
lcd.cls();
lcd.rowcol(1,1);
lcd.puts(“Enter two-digit KA”);
lcd.rowcol(2,1);
lcd.puts("~");

/// Get user input for KA and make sure it’s two-digits long before storing into EEPROM (or somewhere)
for (int i = 0; i < 2;){
if(!lcd.keyint()) {
int tmp = lcd.key();
tmp+=‘0’;
lcd.putch(tmp);
input_KA = tmp;

  • i = i +1;*
  • } *
  • }*
  • //// Finish geting user input*
  • lcd.cls();*
  • lcd.puts("KA Updated to ");*
  • lcd.putch(input_KA[0]);*
  • lcd.putch(input_KA[1]);*

KA = 10*input_KA[0]+input_KA[1] - 528;

  • delay(500);*

  • lcd.cls();*

  • return; *

  • choice = 11;*

  • }*

  • /// End Get input *

  • //if B is pressed do following*

  • {*

  • if(choice == 11){*

  • lcd.cls();*

  • return;}*
    }

  • }[/color][/size]*
    So this is working now, except for the fact that I have to multiply the first digit by ten in order to get the numbers to work out… meaning if a user types in 12 I have to do 1x10+2 to get 12 instead… I had to subtract 528 which is some number coming out of some place, I’m presuming it’s a character code of some sort?
    I hope this will work OK when it comes time to enter 4-digit times and dates, etc…
    Thanks,
    Armen

So this is working now, except for the fact that I have to multiply the first digit by ten in order to get the numbers to work out... meaning if a user types in 12 I have to do 1x10+2 to get 12 instead...

I'm not sure why this surprises/amazes/disappoints you. You asked the user to press two keys. Somewhere along the line some code needs to multiply the first by ten (to get it in the tens place) and add the second (int the ones place).

You could have made the array one element larger, NULL terminated the array, and let the atoi() function do it.

I had to subtract 528 which is some number coming out of some place, I'm presuming it's a character code of some sort?

Here is the reason:

              int tmp = lcd.key();
                          tmp+='0';

The key() function returns the number that is printed on the key (0, 1, 2, etc.). To this you add '0' (whose ASCII value is 48).

                          input_KA[i] = tmp;
        KA = 10*input_KA[0]+input_KA[1] - 528;

Since input_KA[0] is 48 too high, and intput_KA[1] is also 48 too high, and (10 * 48) * 48 = 528, you need to subtract 528 to make the value come out right.

As far as the lazy remark, I apologize if I offended you. But, really, how much harder was this way? You needed to put the right character in the right position in the array. With only two characters, it really isn't that hard to keep track of where a character goes.

Now, if you were to handle some character as a backspace key, it gets more challenging. Might want to consider that.

As mentioned on my screen the last post on this topic was more than 120 days ago, but....

Paul, I have the same configuration as Armen, but a different problem. As I see your respons I think you could help me

The characters I see on the LCD using the demo program do not correspond with the Characters on the Buttons. The * and # are missing at all but therefor I get An E and F. But the squence of characters differs Only changing the sequence in the array didn't help: const char kb[]={0x7d,0xee,0xed,0xeb,0xde,0xdd,0xdb,0xbe,0xbd,0xbb,0xe7,0xd7,0xb7,0x77,0x7e,0x7b}; I even didn't find somewhere a conversion between 1,2,3 et and the array parameters.

Do you know a direction to solve this?

The characters I see on the LCD using the demo program do not correspond with the Characters on the Buttons.

Using what demo program? Show your code.

kb[]={0x7d,0xee,0xed,0xeb,0xde,0xdd,0xdb,0xbe,0xbd,0xbb,0xe7,0xd7,0xb7,0x77,0x7e,0x7b};

Why is this array full of hex values? What do they mean?