[SOLVED] TFT keypad need help on coding

Hi,

I have a tft lcd touch and rtc on my arduino, i drew 0 to 9 numbers on the lcd and have the x,y touch coordinates to define the 10 numbers. I want to do is afther pressing to numbers ex 1 and 3 (13) send them to rtc ( ds1307setup(); ) i change the numers in ds1307set(DS1307_....,mi); to diferent int in order to geting the touch data but dont now how to transform the x,y to a int.
I need to "store" 5 "var" before send the ds1307setup(); (year = int y, month = int m, day = int d....)

ds1307set(DS1307_SEG,1);
ds1307set(DS1307_MIN,mi); // mi
ds1307set(DS1307_HR,h); // h
ds1307set(DS1307_DdS,ds); // ds
ds1307set(DS1307_DMES,dm); // dm
ds1307set(DS1307_MTH,me); // me
ds1307set(DS1307_ANO,a); // a

Please help me or if there is a example made point me there.

Thankz

Paulo

You mean the x and y coordinates? Just use IF/ELSE statements.

Example:
if x == 0 and y == 3, button 3 was pressed.
if x == 1 and y == 5, button 7 was pressed.

You have to map out where each button its and set it in the IF/ELSE statements. You will need 2 X coords(left / right of button) and 2 Y coords(top / bottom of button) to do it properly.

Hi,

Thanks, coordinates part i have done just dont no how i can put it in a int to send to the rtc.

Thankz

Paulo

Arrays and the atoi() function will help you.

Im new to this can you please write a small example?

Thankz

Paulo

Google atoi() and you will get plenty of examples

I have done but cant put it to work =(

Post the code that does not work and describe what should happen and what actually happens.

I dont have now with me, later at home i will posted but i think i used string not array ( i cant understand how fill arrays..)

if (page == 70 && p.y > 211 && p.y < 231 &&  p.x > 84 && p.x <104 ){ 
      tft.setTextSize(3); 
      tft.fillRect(82, 201, 25, 25, BLUE); 
      tft.setCursor(82, 201);
      tft.println ("0"); 
     myString +=0;
    }
    else if  (page == 70 && p.y > 290 && p.y < 310 &&  p.x > 190 && p.x <215){ 
      tft.setTextSize(3); 
      tft.fillRect(110, 201, 25, 25, BLUE); 
      tft.setCursor(110, 201);
      tft.println ("1"); 
      myString +=1;
    }  


     if (page == 70 && p.y > 126 && p.y < 146 &&  p.x > 83 && p.x <103){ 
      tft.fillRect(30, 201, 220, 21, BLUE);  
      tft.drawString(100, 201, "VALIDADO", WHITE, 3); 
     tft.fillRect(1, 50, 25, 25, RED);  
      tft.setTextSize(3); 
      tft.setCursor(1, 50);

      a=atoi(myString);
      ds1307setup();
    }

Arrays
http://arduino.cc/en/Reference/Array

Full code please.

Please teach me,

I need example 4 bytes i declare:

int myInts[4];

if (page == 70 && p.y > 211 && p.y < 231 && p.x > 84 && p.x <104 ){
tft.setTextSize(3);
tft.fillRect(82, 201, 25, 25, BLUE);
tft.setCursor(82, 201);
tft.println ("0");
myInts[0] == 0,
}
else if (page == 70 && p.y > 290 && p.y < 310 && p.x > 190 && p.x <215 && q==1){
tft.setTextSize(3);
tft.fillRect(110, 201, 25, 25, BLUE);
tft.setCursor(110, 201);
tft.println ("1");
myInts[1] == 1,
}

if (page == 70 && p.y > 126 && p.y < 146 && p.x > 83 && p.x <103){
tft.fillRect(30, 201, 220, 21, BLUE);
tft.drawString(100, 201, "VALIDADO", WHITE, 3);
tft.fillRect(1, 50, 25, 25, RED);
tft.setTextSize(3);
tft.setCursor(1, 50);

a=atoi( myInts[0] ,myInts[1]);
ds1307setup();
}

int myInts[4];

does declare an array of 4 ints but

myInts[0] == 0,

does not store a value in the array

a = atoi(myInts);

You should check for a special character button like * or # and if any of those are pressed it convert the array to an int. If those are NOT pressed, use a variable (int counter;) to add number to the array.

Example.

if(press != '*' || press != '#') {
myInts[counter++] = press;
}
else {
a = atoi(myInts);
}

Thanks master,

One question how do i store a value in the array afther number 0 is pressed?

if (page == 70 && p.y > 211 && p.y < 231 && p.x > 84 && p.x <104 ){
tft.setTextSize(3);
tft.fillRect(82, 201, 25, 25, BLUE);
tft.setCursor(82, 201);
tft.println ("0");
myInts ????
}

Same way. the only time it stops entering number is when one of those special characters are pressed. You should also clear the array afterwards with a while loop.

while(counter != 0) { // this can be used for any size array.
myInts[counter--] = 0;
}

@HazardsMind
Why would you call atoi(), which expects a NULL terminated array of chars, with an array of ints?

If he researched the atoi function, then he should know that it needs to be char null terminated. What I gave him was just an example to build on.

OP, your numbers must be chars, not actual ints. '1','2','3'... and so on.

HazardsMind:
Same way
}

My doubts is afther pressing a number how do i store it? in the array in a char??
Please write example they way i talking about (my Inglish is not very good)

thankz

You said you already made a map of the buttons.

if (page == 70 && p.y > 211 && p.y < 231 &&  p.x > 84 && p.x <104  ){ // im guessing button ZERO
      tft.setTextSize(3); 
      tft.fillRect(82, 201, 25, 25, BLUE); 
      tft.setCursor(82, 201);
      tft.println ("0"); 
      myInts[counter++] = '0'; // *** this is the setup needed *** the numbers must go between single quotes '  '
                               // Everytime you press a button, counter updates and the char is stored
                               // If special button is pressed, convert data in array.
    }
    else if  (page == 70 && p.y > 290 && p.y < 310 &&  p.x > 190 && p.x <215 && q==1){ // Button ONE
      tft.setTextSize(3); 
      tft.fillRect(110, 201, 25, 25, BLUE); 
      tft.setCursor(110, 201);
      tft.println ("1"); 
      myInts[counter++] = '1';
    }
    .  TWO
    .  THREE
    .  FOUR
  And so on

Added: You also need to make sure you set the counter back to zero after you convert the array to an int.

Thankz a lot, afther i press 0 and then 1 i press the special button convert data in array i get myInts[0] = 0 and myInts[1] = 1 and myInts[] = 01 write? then a = atoi(myInts);

ok?