Debounce Touch Screen?

Mega, with TFT,

Having designed my menu structure that contains multiple buttons, my focus has turned to correcting the touch behavior. Ideally to be responsive like a latch rather than a continuous stream? When I touch my number “One” soft button, I get a stream of button presses,(example “1111111…”) regardless of how fast I can touch screen. Basically for as long as I hold the button. Not ideal in my case. I actually want to capture the touch and then store a “1” upon release of the soft button, into a variable? Currently a string TPno.

Action desired is similar to the traditional calculator. Select a number, add it to a display, select number and concat to the previous number and display. Down the road, I will use this 6 digit number to create a directory on the SD card, baby steps right now focused on debouncing the touch screen behavior.

Any suggestions how to wrap code around this to achieve desired results?

 if (page == 5)
 {

     if (p.x > 50-12 && p.x < 50+12 && p.y > 30-12 && p.y < 30+12)   //1
     {
       BtCount +1;
       TPno="1";
       TPDis();
      }

...
}

So, is this stream of '1's something that the screen itself is doing? Or is it that you are getting a series of "touch on/touch off" messages?

I have a debounce library at Home · PaulMurrayCbr/DebounceInput Wiki · GitHub which could probably be used for the purpose. You'd be looking at using DebounceFilter4ms · PaulMurrayCbr/DebounceInput Wiki · GitHub and feeding the touch on/touch off data into it. Id have to add a method to get the state given only isolated on/off data rather than continuous data.

The soft button does what it is expected to do and sends the value assigned to the soft button, but I can't get on and off the button fast enough. I don't understand how to "count" the time the button is touched and then send the value one time. Or something to that effect. thanks

You don't seem to have posted the code that gets the values from the touch screen - which seems strange considering that is the problem you are presenting.

Post a complete program.

Without seeing your code my inclination would be to have a short interval (perhaps 50 millisecs) between reading the values from the touch screen.

...R

Its the same ole stuff as the example code.

void loop()

  TSPoint p = ts.getPoint();
    // if sharing pins, you'll need to fix the directions of the touchscreen pins
  //pinMode(XP, OUTPUT);
  pinMode(XM, OUTPUT);
  pinMode(YP, OUTPUT);
  //pinMode(YM, OUTPUT);

  // we have some minimum pressure we consider 'valid'
  // pressure of 0 means no pressing!

  if (p.z > MINPRESSURE && p.z < MAXPRESSURE)
  {
    
     // scale from 0->1023 to tft.width
    p.x = tft.width()-(map(p.x, TS_MINX, TS_MAXX, 0,tft.width()));  //swapped
    p.y = tft.height()-(map(p.y, TS_MINY, TS_MAXY, 0,tft.height()));  //swapped

//....
  
  if (page == 5)
   {

       if (p.x > 50-12 && p.x < 50+12 && p.y > 30-12 && p.y < 30+12)   //1
       {
         BtCount +1;
         TPno="1";
         TPDis();
        }
    }
}

retexas:
Its the same ole stuff as the example code.

But it is still not a complete program. Stop wasting our time as well as yours.

...R