Skip to content

Touch

Warning

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

Configure

Ensure the configuration file enables touch

#define TOUCH_MODE USE_TOUCH_YES

and defines the required pins touchReset and touchInt.

    .touchInt = 8, ///< EXT3-Touch pin 3 Red -> GPIO8
    .touchReset = 6, ///< EXT3-Touch pin 4 Orange -> GPIO6

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 generates the interrupt while the library manages the events.

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

The touch controller offers two optimised power modes, one automatic and another manual.

The automatic mode is managed by the touch controller. The controller enters stand-by mode after a period of inactivity and exits it when the panel is touched. The GPIOs for the touch interrupt are not affected as they are required to manage the reset and trigger the wake-up event.

The manual mode is managed by the system with two functions to enter and exit deep sleep.

  • The function suspendTouch() turns the touch controller off and deactivates the I²C bus.

  • The function resumeTouch() resets the touch controllers and reactivates the I²C bus.

Warning

The functions suspendTouch() and resumeTouch() should not be used if other devices share the same I²C bus.

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;
    }
}