I'm just here looking for a good way to display a keypad on a touch screen shield. Specific model is http://imall.iteadstudio.com/im120417021.html. Basically, the idea is for the user to input numeric values and then count down those values. Basically, just a timer. Is there an easy way to make a keypad on the touch screens or am I stuck using, myGLCD.drawRoundRect a bunch of times?

Yea, its not hard. I made a password screen that uses a touch screen keypad. What libraries are you using, UTFT and UTouch?

There is a keypad sampleUTouch sketch that works well Too..

Doc

Okay, so I have a keypad now, but the way it is programmed makes it a bit counter-intuitive. When you push the first number, it automatically goes to the tens place, so to get the number "1" you have to push "0" and then "1". Here is an excerpt from the code:

```
if((y>90) && (y<135))
{
sets = stCurrent[0] * 10 + stCurrent[1];
stCurrent[0] = 0;
stCurrent[1] = 0;
stCurrentLen = 0;
setscreen = false;
```

The reason it does this is obvious, that's what the code says to do. Is there an easy way to make the code accept a single digit at a time, and tack additional digits onto the end of a number? I feel like I might be over-thinking this one...

Yes don't do the *10 for the first key but subsequent ones.

A counter and if statement should see you right.

I hate to be a burden, but could you explain what you mean by that, Mike? A counter I can do, but how would I create and if statement to say "if only 1 number is input, then it goes in the one's place, otherwise it goes in the tens place"? The way the code is setup right now, the first digit pressed goes into stCurrent[0], and the second goes into stCurrent[1]. These values are then used to determine the value of "sets", which is used in other places of the code to determine how many times the code should loop. If I don't *10 the value, then I'll need to redefine "sets". I just tried to do this with a global placeholder that I called val2. The two sections of code that affect this are as follows:

```
void updateStr(int val)
{
myGLCD.setFont(UbuntuBold);
myGLCD.setBackColor(255, 255, 255);
myGLCD.setColor(0, 0, 0);
if (stCurrentLen<2)
{ if (stCurrentLen = 0) {
stCurrent[stCurrentLen+1]=val;
myGLCD.printNumI(stCurrent[stCurrentLen+1], 130 , 50);
val2 = val;
}
else if (stCurrentLen = 1) {
stCurrent[stCurrentLen - 1] = val2;
stCurrent[stCurrentLen] = val;
myGLCD.printNumI(stCurrent[stCurrentLen - 1], 105, 50);
myGLCD.printNumI(stCurrent[stCurrentLen], 130, 50);
}
}
stCurrentLen++;
}
```

and

```
while(setscreen)
{
myGLCD.setFont(UbuntuBold);
myGLCD.setBackColor(255, 255, 255);
myGLCD.setColor(0, 0, 0);
myGLCD.print("SETS>", 10, 10);
if(myTouch.dataAvailable())
{
delay(100);
myTouch.read();
x = myTouch.getX();
y = myTouch.getY();
if((x>60) && (x<230))
{
getNum(x, y);
updateStr(n);
//myGLCD.printNumI(n, 10, 50);
}
if ((x>10) && (x<50))
{
if((y>90) && (y<135))
{
sets = stCurrent[0] * 10 + stCurrent[1];
stCurrent[0] = 0;
stCurrent[1] = 0;
stCurrentLen = 0;
setscreen = false;
```

I realize the second group is incomplete. I've just pulled the bits out of the code that affect the current operation that I'm troubleshooting.

The first group is the group that I've been working on. It originally was this:

```
void updateStr(int val)
{
myGLCD.setFont(UbuntuBold);
myGLCD.setBackColor(255, 255, 255);
myGLCD.setColor(0, 0, 0);
if (stCurrentLen<2)
{
stCurrent[stCurrentLen]=val;
stCurrent[stCurrentLen+1]=0;
stCurrentLen++;
myGLCD.printNumI(stCurrent[0], 105, 50);
myGLCD.printNumI(stCurrent[1], 130, 50);
}
}
```

But I want it to, as I described before, take the first number input as the ones digit, but move that first number input to the tens digit if a second number is input. Digit are determined by the array stCurrentLen, with the [0] being the tens and the [1] being the ones digit, as shown in the operation sets = stCurrent[0] * 10 + stCurrent[1];. Am I on the right track so far? Right now I'm getting an issue where the code will only take the ones digit, and will not allow a second number to be input. It also displays as 05 instead of just 5, which is driving me nuts trying to change.

A counter I can do, but how would I create and if statement to say "if only 1 number is input, then it goes in the one's place, otherwise it goes in the tens place"?

The number of digits entered is irrelevant, if you treat them correctly. Imagine I write a number on a piece of paper, and lay a card over it. I slide the card to the right, uncovering one character at a time. Suppose I wrote 5127 on the paper, and I uncover the 5. You say 5, when I uncover the 5. Now, I uncover the 1. You can determine that the number is 51 without taking your shoes off, can't you? You simply multiply the number you had (5) by 10 (to get 50) and add the new digit (1) to get 51.

Now, i uncover the 2, and you repeat that process (51 * 10 = 510; 510 + 2 = 512), and you do it again when I uncover the last digit.

That's the process you need to implement for your numeric entry system.

That's pretty much what I was trying to do, Paul. My goal with the code was that if only 1 number was input, it would be put into the stCurrent[1] spot, which, in the code, represents the first digit. If a second number is entered (ergo: if stCurrentLen = 1), then the value of stCurrent[1] would be stored in val2, stCurrent[0] would take on the value of val2, and stCurrent[1] would take on the value of val, which is the input. I've tried to do this with val2 declared within the function and as a global variable, but it doesn't work, at least not the way I currently have it written.

Let me write out the process I wish to take place, and maybe this will help me find the problem, or help others find where my logic is flawed, if that is the case.

Input is received in one of the registered number places on the touch screen. The value of this digit is stored as "val", which is then put through the function updateStr(int val), which stores the value of val in the array stCurrent[1], and in the variable val2, which is a placeholder in case a second number is input. The function then increments stCurrentLen (making it 1). The next time the function is called, it checks that stCurrentLen is less than 2, which it is, then, since stCurrentLen = 1, it runs through the alternate statement, which stores the value of val2 into stCurrent[0] and the value of the input (val) into stCurrent[1]. It then uses the stored values of the array stCurrent, which should be { val2, val }, to determine the value of the variable "sets".

As I typed this out, I realized the problem. I've been using "=" instead of "==" to check value. Whoops. I was also making it too complicated by trying to reference stCurrentLen in the array instead of just stating which value I wanted to change. Thanks for the help everyone!