Skip to content

Touch

Warning

The touch feature requires a screen with a touch controller and the PDLS_EXT3_Advanced_Fast_Touch library.

Configure

Ensure the configuration file enables touch

#define TOUCH_MODE USE_TOUCH_YES

and defines the required pins touchReset and touchInt.

    .touchReset = 6, ///< Separate touch board -> GPIO6
    .touchInt = 8, ///< Separate touch board -> GPIO8

Use

if (myScreen.getTouchInterrupt())
{
    bool result;
    uint16_t x, y, z, t;

    result = myScreen.getTouch(x, y, z, t);
}

getTouchInterrupt() returns true if the touch controller has raised an interrupt.

getTouch() returns true if an event has been raised, and populates

  • x: x coordinate, according to orientation;
  • y: y coordinate, according to orientation;
  • z: pressure, if the touch controller manages it;
  • t: event, if the touch controller manages it.

There are four events: none, press, release and move.

Note

The scopes of the interrupt and the events may differ. The touch controller manages the interrupt while the library generates the events.

For example, the touch controller raises an interrupt for the press and move events, but not for the release event.

Example

This is the core of the code from example Touch_Draw.ino.

void displayTouchDraw()
{
    uint16_t x, y, z, t;
    uint16_t x0, y0, z0, t0; // previous
    t0 = TOUCH_EVENT_NONE;
    uint16_t count = 0;
    bool result;

    myScreen.setOrientation(myOrientation);

    while (count < 64)
    {
        result = myScreen.getTouch(x, y, z, t);

        if ((t == TOUCH_EVENT_MOVE) or (t0 == TOUCH_EVENT_RELEASE))
        {
            if ((t0 == TOUCH_EVENT_PRESS) or (t0 == TOUCH_EVENT_MOVE))
            {
                myScreen.line(x0, y0, x, y, myColours.black);
                myScreen.flushFast();
                count += 1;
            }
        }

        x0 = x;
        y0 = y;
        t0 = t;
    }
}