Go Down

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

PaulS

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

HazardsMind

#16
Feb 06, 2013, 05:32 pm Last Edit: Feb 06, 2013, 05:35 pm by HazardsMind Reason: 1
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.
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

camolas

#17
Feb 06, 2013, 05:38 pm Last Edit: Feb 06, 2013, 05:46 pm by camolas Reason: 1

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

HazardsMind

#18
Feb 06, 2013, 05:49 pm Last Edit: Feb 06, 2013, 05:55 pm by HazardsMind Reason: 1
You said you already made a map of the buttons.

Code: [Select]
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.
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

camolas

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?

 

HazardsMind

myInts[0] = '0' single quotes.

The first zero will drop out, leaving you with just 1, not 01.
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

camolas

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

PaulS

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.

camolas


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

PaulS

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.

camolas

Code: [Select]
[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

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy