Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: Question about the programming of touch screens

  1. #1

    Question about the programming of touch screens

    Hi

    I have progammed a code with a touch screen (librarie Adafruit_FT6206.h). This touch screen runs perfect if I use only one form.

    If I use a second form, the touch functionality from the first form is also additional used and I have wrong things on the screen....

    Is it possible to end the using of the touch screen on the first form and restart it at the next form with the new buttons??

    I have entered the code of one form:

    Code:
    void TouchEingabe()
    {
      // See if there's any  touch data for us
      
      while (TouchEnde == false)
      {
      if (ts.touched())
      {   
        
        // Retrieve a point  
        TS_Point p = ts.getPoint(); 
        // rotate coordinate system
        // flip it around to match the screen.
        p.x = map(p.x, 320, 0, 0, 320);
        p.y = map(p.y, 480, 0, 0, 480);
        int y = display.height() - p.x;
        int x = p.y;
    
        if((x >= 25) && (x <= 95)) {
            if ((y >= 140) && (y <= 210)) {
              z = 1;
            }}
        if((x >= 115) && (x <= 185)) {
            if ((y >= 140) && (y <= 210)) {
              z = 2;
            }}
        if((x >= 205) && (x <=275)) {
            if ((y >= 140) && (y <= 210)) {
              z = 3;
            }}
        if((x >= 295) && (x <= 365)) {
            if ((y >= 140) && (y <= 210)) {
              z = 4;
            }}
        if((x >= 385) && (x <= 455)) {
            if ((y >= 140) && (y <= 210)) {
              z = 5;
            }}
        
        if((x >= 25) && (x <= 95)) {
            if ((y >= 230) && (y <= 300)) {
              z = 6; 
            }}
        if((x >= 115) && (x <=185)) {
            if ((y >= 230) && (y <= 300)) {
              z = 7;
            }}
        if((x >= 205) && (x <= 275)) {
            if ((y >= 230) && (y <= 300)) {
              z = 8; 
            }}
        if((x >= 295) && (x <= 365)) {
            if ((y >= 230) && (y <= 300)) {
              z = 9;
            }}
        if((x >= 385) && (x <= 445)) {
            if ((y >= 230) && (y <= 300)) {
              z = 0;
            }}
        if((x >= 25) && (x <=95)) {
            if ((y >= 20) && (y <= 90)) {
              z = 11;
                        
            }}
        if((x >= 355) && (x <= 425)) {
            if ((y >= 20) && (y <= 90)) {
              TouchEnde = true;
              z = 12;
              
            }}
    
        delay (200);
    
        if ((z >= 0) && (z <= 9)){
        kWert = (kWert * 10) + z;
        }
    
        if (z == 11){
          kWert = kWert / 10;
        }
        display.setCursor(160, 35);
        
        if (kWert != kWertAlt) {
        display.fillRoundRect(145, 20, 190, 70, 12,  ILI9488_WHITE);
        display.print(kWert);
        kWertAlt = kWert;
      }}
        
      }}
    Someone an idea how to stop the using of the touch and restart it new in a new form??

    Greetings

    Gary

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    13,921
    Quick read suggest a FORM is a screen layout of some button images.

    A touch on those image areas is calculated as a hit if the conditional code in TouchEingabe() finds the touch point inside one of the tested areas?

    For another Second FORM with unique button image layout, it would require a unique TouchEingabe_Second() set of conditionals where the testing maps to those button images?

    I did this years back and made a structure where a unique structure held the 'button' touch area boundaries. When the images was changed the structure with those details needed to be changed accordingly.

    What I did [in 2015] looks like this : ColorButtonsMark3/ColorButtonsMark3.h

    That was linked from here : ILI9341-and-XPT2046-for-Teensy-Touchscreen-320x240-display

    That is with the PJRC display - but the concept should be the same.

    BTW: I used the Teensy itself to generate the structure output for all those numbers. They were just blocks of buttons written in code and I printed out the structure to the Serial Monitor and then pasted them into the code - and added details as needed to the boundary numbers.

  3. #3
    Senior Member
    Join Date
    Jul 2020
    Posts
    977
    You need to programmatically change the data used for touch event mapping when you change which form is
    presented on the screen. If you make this data-driven this will be more straight-forward. Maintain lists or
    arrays of active rectangles for each form (which can be used both for drawing and for reacting to touch events).
    When you present a form, switch to the relevant list/array.

    The code you give has hard-wired coordinates in the code - the very opposite of data-driven.

    Alas programming GUI's is quite a task, you are probably better off finding a good library that handles things
    for you with support for callbacks and data-driven definition of menus. There's probably several options
    out there, some giving a full breakdown into model-view-controller paradigm even - I'm not the one
    to ask, but someone will have some good pointers for this.

  4. #4
    Thanks for your answers.

    Yes, I have programmed a form and a touch code for this form. If I push a touch button you will start a new form with a new code for the touch functionality.

    Now I will read and understand your answers. Maybe I will find a way to change my code...

  5. #5
    When we work on TFT's that do not have a dedicated graphics processor, we must "mask actions so that they appear immediate" on the screen. We can achieve this by duplicating screens, whose difference is subtle between the two. As a result we will have dynamic interfaces.

    This concept can also be applied to libraries that allow controlling capacitive or resistive touch panels.

    Another consideration is that we must stop using void loop, since we will be subject to a single cyclical process. To supply it, we can resort to functions with structures of this type:

    Code:
    void MP ()
    {
      // code that runs once
       while (1)
      {
       // cyclic code that can be interrupted by an action on the touch panel
      }
    }
    This way of programming allows independent menus MP1, MP2, MP3, etc, each one with its independent infinite cycle.

  6. #6
    Sometimes it is so easy (if you are a good programmer and everything runs good)....
    While testing I have changed two lines and the touch runs also on the second form...

    Thanks for your ideas and replies.....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •