Go Down

Topic: Denouncing a touchscreen button (Read 439 times) previous topic - next topic

psppb

I have a 2.8" TFT LCD shield from ADAfruit industries and I've figured out how to create buttons at have them "Do stuff" but I am having a problem with Jitter in that all I am using so far is the delay(100); command to try and prevent any jitter. Sometimes it works and sometimes it does not. Any suggestions on how to improve this? The delays are highlighted below.

Thanks!

Code: [Select]
if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
    Serial.print("\tPressure = "); Serial.println(p.z);

   
    // scale from 0->1023 to tft.width
    p.x = map(p.x, TS_MINX, TS_MAXX, tft.width(), 0);
    p.y = map(p.y, TS_MINY, TS_MAXY, tft.height(), 0);
 
    Serial.print("("); Serial.print(p.x);
    Serial.print(", "); Serial.print(p.y);
    Serial.println(")");
   //Setup Complete
   
   //Start Screen
   if (screen == 0){
     Isready = 0;
     tft.fillScreen(BLACK);
     tft.fillRect(20, 20, 200, 40, RED);
     tft.drawRect(20, 20, 200, 40, WHITE);
     tft.setCursor(30, 25);
     tft.setTextColor(WHITE);  tft.setTextSize(2);
     tft.println("START BULILDING");
   
     if (((20 < p.y) && (p.y < 60 )) && ((20 < p.x) && (p.x < 220))) {
       Serial.println("hello screen 0");
       screen  = 1;
       
       delay(100);
     }
     else{
       Serial.println("Not Red Button");
       screen = 0;
     }
  }
  else if (screen == 1){
     Isready = 1;
     tft.fillScreen(BLACK);
     tft.fillRect(20, 20, 200, 40, GREEN);
     tft.drawRect(20, 20, 200, 40, WHITE);
     tft.setCursor(40, 30);
     tft.setTextColor(WHITE);  tft.setTextSize(2);
     tft.println("  Ghost Block");
     
     tft.fillRect(20, 80, 200, 40, BLUE);
     tft.drawRect(20, 80, 200, 40, WHITE);
     tft.setCursor(40, 90);
     tft.setTextColor(WHITE);  tft.setTextSize(2);
     tft.println(" UnGhost Block");
     
     Serial.println("running");
       
     }
   
     if (((20 < p.y) && (p.y < 60 )) && ((20 < p.x) && (p.x < 220))) {
       Serial.println("hello screen 1");
       screen  = 1;
       delay(100); // *****************// Here is the problem
     }
     else if (((80 < p.y) && (p.y < 120 )) && ((20 < p.x) && (p.x < 220))) {
       Serial.println("hello screen 3");
       screen  = 0;
       delay(100); // *****************// Here is the problem
     }
     else{
       Serial.println("Not green Button");
       screen = 1;
     }
  }

if ((screen == 1) && (Isready == 1)){
    readAnalog_pin();
}

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