Touch in Area
The Inkplate 6FLICK_Touch_In_Area example shows how to detect touch input within a specific rectangular area of the Inkplate 6FLICK's screen. This is useful for creating interactive buttons or UI zones without relying on predefined widgets.
Touch in Area
This example uses display.touchInArea(x1, y1, x2, y2) to determine if the screen has been touched within a specific region, enabling basic interactive UI design.
ℹ️
You can use
touchInArea() in both black-and-white (1-bit) and grayscale (3-bit) modes. For optimal responsiveness, avoid calling display updates within tight touch polling loops unless needed.#include "Inkplate.h"
int x_position = 50;
int y_position = 50;
Inkplate display(INKPLATE_1BIT);
void setup()
{
// put your setup code here, to run once:
Serial.begin(115200);
display.begin();
display.clearDisplay();
display.setCursor(100, 300);
display.setTextSize(3);
display.print("Touch button example. Touch the black button.");
display.display();
delay(3000);
display.clearDisplay();
// Init touchscreen and power it on after init (send false as argument to put it in deep sleep right after init)
if (display.touchscreen.init(true))
{
Serial.println("Touchscreen init ok");
}
else
{
Serial.println("Touchscreen init fail");
while (true);
}
//Draw initial rectangle
display.fillRect(x_position, y_position, 100, 50, BLACK);
display.display();
}
void loop()
{
//Touch in area checks if touch ocured in given coordinates
if(display.touchscreen.touchInArea(x_position, y_position, 100, 50))
{
x_position += 100;
y_position += 100;
if(y_position < 660)
{
display.clearDisplay();
display.fillRect(x_position, y_position, 100, 50, BLACK);
display.partialUpdate();
delay(100);
}
else//Reseting rectangle position and doing full refresh
{
x_position = 50;
y_position = 50;
display.clearDisplay();
display.fillRect(x_position, y_position, 100, 50, BLACK);
display.display();
}
}
}
display.touchInArea()
Checks if a touch event occurred within a defined rectangular area on the screen.
Returns value: Returns true if a touch is detected within the specified area, false otherwise.
Function parameters:
| Type | Name | Description |
|---|---|---|
int | x1 | X coordinate of the top-left corner of the area. |
int | y1 | Y coordinate of the top-left corner of the area. |
int | x2 | X coordinate of the bottom-right corner of the area. |
int | y2 | Y coordinate of the bottom-right corner of the area. |
Full examples
Check out the full examples:
Inkplate6FLICK_Touch_In_Area.ino
Example showing how to detect if a touch event occurs within a rectangular area on the Inkplate 6FLICK.