Loading...
Pages: 1 [2]   Go Down
Author Topic: [SOLVED] TFT keypad need help on coding  (Read 292 times)
0 Members and 1 Guest are viewing this topic.
Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 311
Posts: 35470
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

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.
« Last Edit: February 06, 2013, 11:35:37 am by HazardsMind » Logged

UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino

Arduino Tutorials, coming soon.

"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown

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

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
« Last Edit: February 06, 2013, 11:46:30 am by camolas » Logged

Queens, New York
Online Online
Edison Member
*
Karma: 27
Posts: 1547
"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 said you already made a map of the buttons.

Code:
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.
« Last Edit: February 06, 2013, 11:55:42 am by HazardsMind » Logged

UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino

Arduino Tutorials, coming soon.

"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown

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

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?

   
Logged

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

myInts[0] = '0' single quotes.

The first zero will drop out, leaving you with just 1, not 01.
Logged

UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino

Arduino Tutorials, coming soon.

"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown

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

I need to "store" the 01 how can i do this?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 311
Posts: 35470
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I need to "store" the 01 how can i do this?
Why? There is ABSOLUTELY no difference between 1, 01, 0x01, 0x0001, 0b00000001, and B00000001.
Logged

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

Quote
I need to "store" the 01 how can i do this?
Why? There is ABSOLUTELY no difference between 1, 01, 0x01, 0x0001, 0b00000001, and B00000001.

If i press 1 and then 1 again i will get 11? because let me say i want to set the day for 11 in rtc

Thanks
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 311
Posts: 35470
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
If i press 1 and then 1 again i will get 11?
Maybe. Or, maybe you'll get "11" or maybe an old banana. We can't see what code you are now using.
Logged

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

Code:
[quote author=PaulS link=topic=147319.msg1107087#msg1107087 date=1360178171]
[quote]If i press 1 and then 1 again i will get 11?[/quote]
Maybe. Or, maybe you'll get "11" or maybe an old banana. We can't see what code you are now using.
[/quote]

There are the "old banana" ..... many thanks to HazardsMind


[code if (page == 70 && p.y > 134 && p.y < 162 &&  p.x > 145 && p.x <185 && x==1){
      if (setC==1){
        qx=100;
        qw=193;
      }
      if (setC==2){
        qx=130;
        qw=193;
      }
      tft.setTextSize(4);
      tft.fillRect(qx, qw, 21, 29, BLACK);
      tft.setCursor(qx, qw);
      // tft.setCursor(100, 193);
      myInts[counterrtc++] = '0';
      tft.println ("0");
      setC = setC + 1;
      delay(1000);
    }
    if  (page == 70 && p.y > 290 && p.y < 337 &&  p.x > 195 && p.x <230 && x==1){ 
      if (setC==1){
        qx=100;
        qw=193;
      }
      if (setC==2){
        qx=130;
        qw=193;
      }
      tft.setTextSize(4);
      tft.fillRect(qx, qw, 21, 29, BLACK);
      tft.setCursor(qx, qw);
      myInts[counterrtc++] = '1';
      tft.println ("1");
      setC = setC + 1;
      delay(1000);
    } 
    if  (page == 70 && p.y > 238 && p.y < 275 &&  p.x > 195 && p.x <230 && x==1){
      if (setC==1){
        qx=100;
        qw=193;
      }
      if (setC==2){
        qx=130;
        qw=193;
      }
      tft.setTextSize(4);
      tft.fillRect(qx, qw, 21, 29, BLACK);
      tft.setCursor(qx, qw);
      myInts[counterrtc++] = '2';
      tft.println ("2");
      setC = setC + 1;
      delay(1000);
    } 
    if  (page == 70 && p.y > 187 && p.y < 226 &&  p.x > 195 && p.x <230 && x==1){
      if (setC==1){
        qx=100;
        qw=193;
      }
      if (setC==2){
        qx=130;
        qw=193;
      }
      tft.setTextSize(4);
      tft.fillRect(qx, qw, 21, 29, BLACK);
      tft.setCursor(qx, qw);
      myInts[counterrtc++] = '3';
      tft.println ("3");
      setC = setC + 1;
      delay(1000);
    } 
    if  (page == 70 && p.y > 137 && p.y < 173 &&  p.x > 195 && p.x <230 && x==1){
      if (setC==1){
        qx=100;
        qw=193;
      }
      if (setC==2){
        qx=130;
        qw=193;
      }
      tft.setTextSize(4);
      tft.fillRect(qx, qw, 21, 29, BLACK);
      tft.setCursor(qx, qw);
      myInts[counterrtc++] = '4';
      tft.println ("4");
      setC = setC + 1;
      delay(1000);
    } 
    if  (page == 70 && p.y > 83 && p.y < 119 &&  p.x > 195 && p.x <230 && x==1){
      if (setC==1){
        qx=100;
        qw=193;
      }
      if (setC==2){
        qx=130;
        qw=193;
      }
      tft.setTextSize(4);
      tft.fillRect(qx, qw, 21, 29, BLACK);
      tft.setCursor(qx, qw);
      myInts[counterrtc++] = '5';
      tft.println ("5");
      setC = setC + 1;
      delay(1000);
    } 
    if  (page == 70 && p.y > 30 && p.y < 69 &&  p.x > 195 && p.x <230 && x==1){
      if (setC==1){
        qx=100;
        qw=193;
      }
      if (setC==2){
        qx=130;
        qw=193;
      }
      tft.setTextSize(4);
      tft.fillRect(qx, qw, 21, 29, BLACK);
      tft.setCursor(qx, qw);
      myInts[counterrtc++] = '6';
      tft.println ("6");
      setC = setC + 1;
      delay(1000);
    } 
    if  (page == 70 && p.y > 290 && p.y < 337 &&  p.x > 145 && p.x <185 && x==1){
      if (setC==1){
        qx=100;
        qw=193;
      }
      if (setC==2){
        qx=130;
        qw=193;
      }
      tft.setTextSize(4);
      tft.fillRect(qx, qw, 21, 29, BLACK);
      tft.setCursor(qx, qw);
      myInts[counterrtc++] = '7';
      tft.println ("7");
      setC = setC + 1;
      delay(1000);
    } 
    if  (page == 70 && p.y > 238 && p.y < 275 &&  p.x > 145 && p.x <185 && x==1){
      if (setC==1){
        qx=100;
        qw=193;
      }
      if (setC==2){
        qx=130;
        qw=193;
      }
      tft.setTextSize(4);
      tft.fillRect(qx, qw, 21, 29, BLACK);
      tft.setCursor(qx, qw);
      myInts[counterrtc++] = '8';
      tft.println ("8");
      setC = setC + 1;
      delay(1000);
    } 
    if  (page == 70 && p.y > 187 && p.y < 226 &&  p.x > 145 && p.x <185 && x==1){
      if (setC==1){
        qx=100;
        qw=193;
      }
      if (setC==2){
        qx=130;
        qw=193;
      }
      tft.setTextSize(4);
      tft.fillRect(qx, qw, 21, 29, BLACK);
      tft.setCursor(qx, qw);
      myInts[counterrtc++] = '9';
      tft.println ("9");
      setC = setC + 1;
      delay(1000);
    } 

    if (page == 70 && p.y > 80 && p.y < 118 &&  p.x > 145 && p.x <185 && x==1){ // VERDE VALIDA
      //tft.fillRect(30, 201, 50, 21, BLUE); 
      // tft.drawString(100, 201, "VALIDADO", WHITE, 3);
      tft.fillRect(180, 193, 42, 29, BLACK); 
      tft.setTextSize(4);
      tft.setCursor(180, 193);
      setC = 0;
      x=0;
      counterrtc = 0;
      selec = atoi(myInts);
      tft.println (selec);
      if (zz==1){
        a = selec;
        zz=0;
      }
      if (zz==2){
        me = selec;
        zz=0;
      }
      if (zz==3){
        ds = selec;
        zz=0;
      }
      if (zz==4){
        dm = selec;
        zz=0;
      }
      if (zz==5){
        h = selec;
        zz=0;
      }
      if (zz==6){
        mi = selec;
        zz=0;
      }
      while(counterrtc != 0) { // this can be used for any size array.  myInts[counterrtc] = '\0';
        myInts[counterrtc--] = 0;
      }
      delay(2000);
      tft.fillRect(20, 193, 220, 33, BLACK);
    }
    if (page == 70 && p.y > 34 && p.y < 66 &&  p.x > 145 && p.x <185 ){ // VERMELHO APGAGA // VERMELHO APGAGA // VERMELHO APGAGA
      tft.fillRect(20, 193, 220, 33, BLACK);
      tft.setTextSize(4);
      tft.setCursor(100, 193);
      counterrtc = 0;
      selec = '\0';
      while(counterrtc != 0) { // this can be used for any size array.  myInts[counterrtc] = '\0';
        myInts[counterrtc--] = 0;
      }
      myInts[2] = '\0';
    }

    if  (page == 70 && p.y > 265 && p.y < 330 &&  p.x > 110 && p.x < 135 ){ // ANO ANO ANO ANO
      tft.setTextSize(4);
      tft.fillRect(20, 193, 70, 29, BLACK);
      tft.setCursor(20, 193);
      tft.println ("ANO");
      x=1;
      setC=1;
      zz=1;
      delay(1000);
    } 
    if  (page == 70 && p.y > 190 && p.y < 250 &&  p.x > 110 && p.x < 135 ){ // MES MES MES MES  Y  190  250   X  110  135   
      tft.setTextSize(4);
      tft.fillRect(20, 193, 70, 29, BLACK);
      tft.setCursor(20, 193);
      tft.println ("MES");
      zz=2;
      x=1;
      setC=1;
      //  char   mes[2];
      // byte coumes;
      delay(1000);
    } 
    if  (page == 70 && p.y > 105 && p.y < 167 &&  p.x > 110 && p.x < 135 ){ //DIA SEM DIA SEM DIAS EM
      tft.setTextSize(2);
      tft.fillRect(20, 193, 80, 31, BLACK);
      tft.fillRect(25, 224, 75, 2, BLACK);
      tft.setCursor(40, 193);
      tft.println ("DIA");
      tft.setCursor(25, 210);
      tft.println ("SEMANA");
      zz=3;
      x=1;
      setC=1;
      //  char   mes[2];
      // byte coumes;
      delay(1000);
    } 
    if  (page == 70 && p.y > 25 && p.y < 90 &&  p.x > 110 && p.x < 135 ){ //DIA DIA DIA DIA DIA DIA DIA DIA DIA DIA   
      tft.setTextSize(4);
      tft.fillRect(20, 193, 70, 29, BLACK);
      tft.setCursor(20, 193);
      tft.println ("DIA");
      zz=4;
      x=1;
      setC=1;
      //  char   mes[2];
      // byte coumes;
      delay(1000);
    } 
    if  (page == 70 && p.y > 265 && p.y < 330 &&  p.x > 65 && p.x < 100 ){ //HORA HORA HORA HORA HORA
      tft.setTextSize(3);
      tft.fillRect(20, 193, 70, 29, BLACK);
      tft.setCursor(20, 198);
      tft.println ("HORA");
      zz=5;
      x=1;
      setC=1;
      //  char   mes[2];
      // byte coumes;
      delay(1000);
    } 
    if  (page == 70 && p.y > 190 && p.y < 250 &&  p.x > 65 && p.x < 100 ){ // MINUTO MINUTO MINUTO MINUTO
      tft.setTextSize(4);
      tft.fillRect(20, 193, 70, 29, BLACK);
      tft.setCursor(20, 193);
      tft.println ("MIN");
      zz=6;
      x=1;
      setC=1;
      //  char   mes[2];
      // byte coumes;
      delay(1000);
    } 
    if  (page == 70 && p.y > 105 && p.y < 167 &&  p.x > 65 && p.x < 100 ){ // EVENTO EVENTO EVENTO EVENTO
      tft.setTextSize(3);
      tft.fillRect(20, 193, 220, 33, BLACK);
      tft.setCursor(20, 198);
      tft.println ("EVENTO");
      delay(1500);
      tft.fillRect(20, 193, 220, 33, BLACK);
    } 
    if  (page == 70 && p.y > 25 && p.y < 90 &&  p.x > 65 && p.x < 100 ){ // ENTER ENTER ENTER ENTER ENTER
      tft.setTextSize(4);
      tft.fillRect(20, 193, 220, 33, BLACK);
      tft.setCursor(20, 193);
      tft.println ("ENTER");
      counterrtc = 0;
      selec = '\0';
      while(counterrtc != 0) { // this can be used for any size array.  myInts[counterrtc] = '\0';
        myInts[counterrtc--] = 0;
      }
      myInts[2] = '\0';
      ds1307setup();
      delay(2000);
      tft.fillRect(20, 193, 220, 33, BLACK);
    }]

If i can hellp any one please let me know
Logged

Pages: 1 [2]   Go Up
Print
 
Jump to: