IoAbstraction includes support for touch screens. The support is built in layers to allow for different drivers to be added over time. However, at the moment there is support for resistive touch screens on analog pins. This library can work with such touch screens regardless of analog input resolution, as long as the device is supported by IoAbstraction.
As with switches and rotary encoder support, this component deals with debouncing the user input and also working out if the user has selected or held, therefore supporting drag operations.
In order to add touch screen support, first use your library manager to install IoAbstraction. Once this is done, you can either start with the touch screen example or just follow the instructions below.
#include <ResistiveTouchScreen.h> // This is the most basic extension of the touch screen class, it just allows // you to read it's present values, there is also an event driven version. ValueStoringResistiveTouchScreen touchScreen(XPOS_PIN, XNEG_PIN, YPOS_PIN, YNEG_PIN, TouchInterrogator::PORTRAIT);
// If calibration is needed, then you can provide the calibration in terms of // screen edges here. Then we start touchScreen.calibrateMinMaxValues(0.15F, 0.75F, 0.06F, 0.91F); touchScreen.start();
You can read back the values at any time, it is split into three methods, one to determine the current touch status, another to get the X and Y coordinates.
// tell the encoder it is being used for scrolling and needs to be responsive void setUsedForScrolling(bool scrolling) // returns one of NOT_TOUCHED, TOUCHED, HELD, TOUCH_DEBOUNCE TouchState getTouchState() // return a float value between 0 and 1 to indicate screen position getLastX() and getLastY()
To do this instead of using the above
ValueStoringTouchScreenManager you create your own class that extends from
TouchScreenManager. See the Touch interface reference docs for more information.
To do this you create an object that extends from TouchInterrogator, it must indicate touche status in the following method:
virtual TouchState internalProcessTouch( float* ptrX, float* ptrY, TouchRotation rotation, const CalibrationHandler& calib)=0;
See the Touch interface reference docs for more information.