
Step 1. Use the graphic library to draw the four squares representing our buttons.
The required driver function is:
aek_ili9341_drawRect(AEK_LCD_DEV0, 10, 80, 105, 110, ILI9341_COLOR_BLUE);
and the input parameters are:
*@brief Draw a Rectangle
*
*@param[in] dev LCD_Component
*@param[in] x, y top left coordinates
*@param[in] h, w rectangle dimension
*@param[in] color RGB565 color
Step 2. To retrieve the X, Y absolute coordinates of the blue square (bottom left one), touch the vertices of the
blue square one by one in progression.
At every touch detection in the code, a driver function is invoked to read and store the returned position
values. The procedure will be repeated four times to cover all square vertices.
i=0;
for (; ;) {
if (aek_lcd_get_touchFeedback(AEK_LCD_DEV0) != 0U) { // the screen has been
touched
if (i<4) { // we are in calibration phase to identify the blue square
coordinates
aek_lcd_read_touch_pos(AEK_LCD_DEV0, x_value[i], y_value[i]);//store in
the array each vertex position
i++; }//move to next corner
else {
// first time save the extreme corners of the square in the
xx_BlueButton variables
aek_lcd_read_touch_pos(AEK_LCD_DEV0, &x_value. &y_value] // we
are in normal touch detection phase
if ((X)_BlueBotton < x_value && x_value < X1_BlueButton) &&
(Y0_BlueButton< y_value && y_value <
Y1_BlueButton)) { /*do something*/ }
}
// reset the state of LCD Touch in order to detect a new touch.
aek_lcd_set_touchFeedback(AEK_LCD_DEV0)
}
}
The input parameters of the aek_lcd_read_touch_pos() function are:
*@param[in] dev LCD_Component
*@param[in] x coordinate x read
*@param[in] y coordinate y read
The blue square touching area is now identified.We Once received, we read the new position detected
and we compare it with the xx_BlueBotton variables to verify if the touch is on the blue square.
Step 3. To test if the touches are inside or outside the blue square, store the extreme corner of the square in
four xx_BlueBotton variables and wait for the next touch event ("else" case of the above code).
if((X0_BlueButton < x_value && x_value < X1_BlueButton) && (Y0_BlueButton <
y_value && y_value < Y1_BlueButton))
{
// do something
}
UM2939
Usage of graphic and touch libraries example
UM2939 - Rev 1 page 8/28