Pages: [1] 2   Go Down
Author Topic: [SOLVED] TFT keypad need help on coding  (Read 1591 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 89
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: February 07, 2013, 07:22:47 pm by camolas » Logged

Queens, New York
Online Online
Faraday Member
**
Karma: 106
Posts: 3757
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 89
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Queens, New York
Online Online
Faraday Member
**
Karma: 106
Posts: 3757
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Arrays and the atoi() function will help you.
Logged

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 89
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Thankz

Paulo
Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 116
Posts: 4313
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Google atoi() and you will get plenty of examples
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 89
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have done but cant put it to work  smiley-cry
Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 116
Posts: 4313
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 89
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:



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

Logged

Queens, New York
Online Online
Faraday Member
**
Karma: 106
Posts: 3757
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Full code please.
« Last Edit: February 06, 2013, 10:52:10 am by HazardsMind » Logged

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 89
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 116
Posts: 4313
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
int myInts[4];
does declare an array of 4 ints but
Code:
myInts[0] == 0,
does not store a value in the array
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Queens, New York
Online Online
Faraday Member
**
Karma: 106
Posts: 3757
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 89
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Queens, New York
Online Online
Faraday Member
**
Karma: 106
Posts: 3757
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

Pages: [1] 2   Go Up
Jump to: