Go Down

Topic: [SOLVED] TFT keypad need help on coding (Read 1 time) previous topic - next topic

camolas

Feb 06, 2013, 03:27 pm Last Edit: Feb 08, 2013, 01:22 am by camolas Reason: 1
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

HazardsMind

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.

camolas

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

HazardsMind

Arrays and the atoi() function will help you.

camolas

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

Thankz

Paulo

UKHeliBob

Google atoi() and you will get plenty of examples
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

camolas

I have done but cant put it to work  =(

UKHeliBob

Post the code that does not work and describe what should happen and what actually happens.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

camolas

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..)

Code: [Select]




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();
   }


HazardsMind

#9
Feb 06, 2013, 04:49 pm Last Edit: Feb 06, 2013, 04:52 pm by HazardsMind Reason: 1

camolas

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();
    }

UKHeliBob

Code: [Select]
int myInts[4];
does declare an array of 4 ints but
Code: [Select]
myInts[0] == 0,
does not store a value in the array
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

HazardsMind

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);
}

camolas

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 ????
    }

HazardsMind

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;
}

Go Up