Keypad on touchscreen

Hi forum,

While working on a project a faced a problem.
I use a touchscreen as interface to control multple nodes.
The end user should be able to type which node he wants to change.
This works fine for 1-9. But now I faced the follow problem.

How do i make a number like 18, 66, 120?
I mean I cant sum 1+8 cause this will be 9 instand of 18.

Keypad layout:

https://drive.google.com/file/d/0B4n69dT05nvcNUpxeU9VZFV0T3M/view?usp=sharing

My currect code:

while(ok==0){

if ( ctp.touched()) {  
  
  TS_Point p = ctp.getPoint();
  int px = map(p.x, 0, 240, 240, 0);
  int py = map(p.y, 0, 320, 320, 0);


  if ((px > 0) && (px < 40) && (py > 260 ) && (py < 290) )  {
    result=1;}

  if ((px > 40) && (px < 80) && (py > 260 ) && (py < 290) )  {
    result=2;}


  if ((px > 80) && (px < 120) && (py > 260 ) && (py < 290) )  {
    result=3;}

  if ((px > 120) && (px < 160) && (py > 260 ) && (py < 290) )  {
    result=4;}
    
  if ((px > 160) && (px < 200) && (py > 260 ) && (py < 290) )  {
    result=5;}

      
  if ((px > 200) && (px < 240) && (py > 290 ) && (py < 320) )  {
    ok=1;}
 
  }

I hope you people are able to help.
Also sorry for mine bad english.

Greets,

What libraries are you using? I made quite a few keypad sketches for various TFT libraries, odds are I already made one for your library.

I would not do it like this, I would use an array for the numbers/characters and use basic math with a FOR loop to layout the buttons.

if ((px > 0) && (px < 40) && (py > 260 ) && (py < 290) ) {
result=1;}

if ((px > 40) && (px < 80) && (py > 260 ) && (py < 290) ) {
result=2;}

if ((px > 80) && (px < 120) && (py > 260 ) && (py < 290) ) {
result=3;}

if ((px > 120) && (px < 160) && (py > 260 ) && (py < 290) ) {
result=4;}

if ((px > 160) && (px < 200) && (py > 260 ) && (py < 290) ) {
result=5;}

if ((px > 200) && (px < 240) && (py > 290 ) && (py < 320) ) {
ok=1;}

}

Another thing, if you want to join numbers together, you would just use this.
final_number = (final_number * 10) + new_number;

Every time you press a button, the new value gets joined to the final number, until you clear it and start over.

Hello,

(1 * 10) + 8 = 18 :slight_smile:

I dont use a libary at this moment.
And of course you guys are right, its just silly of me that i forgot a easy thing like this.

Thank you very much both of you,