### Initialize and Detect Touch Points Source: https://github.com/arduino-libraries/arduino_gigadisplaytouch/blob/main/docs/README.md Minimal example for Arduino GIGA R1 WiFi to initialize the touch detector and retrieve touch point coordinates. Use this to check if at least one touch occurs on the screen and print its coordinates. ```cpp #include "Arduino_GigaDisplayTouch.h" Arduino_GigaDisplayTouch touchDetector; void setup() { Serial.begin(115200); touchDetector.begin(); } void loop() { uint8_t contacts; GDTpoint_t points[5]; contacts = touchDetector.getTouchPoints(points); if (contacts > 0) { //Check if at least one touch occurs on the screen //Print the coordinates of all simultaneous contacts detected for (uint8_t i = 0; i < contacts; i++) { Serial.print(points[i].x); Serial.print(" "); Serial.println(points[i].y); } //Do something with the touch coordinates } } ``` -------------------------------- ### Initialize Touch and Get Points Source: https://context7.com/arduino-libraries/arduino_gigadisplaytouch/llms.txt Initializes the touch detector and retrieves touch points in a loop. Access individual touch point properties like trackId, x, y, and area. Suitable for polling-based touch detection. ```cpp #include "Arduino_GigaDisplayTouch.h" // GDTpoint_t structure definition: // struct GDTpoint_s { // uint8_t trackId; // Unique identifier for tracking finger across frames // uint16_t x; // X coordinate (0 to display width) // uint16_t y; // Y coordinate (0 to display height) // uint16_t area; // Touch area/pressure estimation // uint8_t pressed; // Press state // }; Arduino_GigaDisplayTouch touchDetector; void setup() { Serial.begin(115200); while (!Serial) {} touchDetector.begin(); } void loop() { GDTpoint_t points[GT911_MAX_CONTACTS]; // GT911_MAX_CONTACTS = 5 uint8_t contacts = touchDetector.getTouchPoints(points); for (uint8_t i = 0; i < contacts; i++) { // Access individual touch point properties uint8_t id = points[i].trackId; // Track finger across multiple frames uint16_t xPos = points[i].x; // Horizontal position uint16_t yPos = points[i].y; // Vertical position uint16_t touchArea = points[i].area; // Touch area size Serial.print("Finger "); Serial.print(id); Serial.print(" at ("); Serial.print(xPos); Serial.print(","); Serial.print(yPos); Serial.print(") area="); Serial.println(touchArea); } delay(10); } ``` -------------------------------- ### Method: begin Source: https://github.com/arduino-libraries/arduino_gigadisplaytouch/blob/main/docs/api.md Initializes the touch controller, preparing it for operation. ```APIDOC ## Method begin ### Description Initialize the touch controller. ### Returns * **bool** - true If the touch controller is successfully initialized, false otherwise. ``` -------------------------------- ### begin() - Initialize Touch Controller Source: https://context7.com/arduino-libraries/arduino_gigadisplaytouch/llms.txt Configures the I2C bus, executes the power-on sequence, and verifies communication with the GT911 controller. ```APIDOC ## begin() ### Description Initializes the touch controller. If LVGL is included, it automatically registers the controller as an input device. ### Response - **bool** - Returns true if initialization succeeds, false otherwise. ``` -------------------------------- ### Initialize Touch Controller with begin() Source: https://context7.com/arduino-libraries/arduino_gigadisplaytouch/llms.txt Configures the I2C bus and verifies communication with the GT911 controller. Automatically registers as an LVGL input device if LVGL is present. ```cpp #include "Arduino_GigaDisplayTouch.h" Arduino_GigaDisplayTouch touchDetector; void setup() { Serial.begin(115200); while (!Serial) { // Wait for serial connection } // Initialize the touch controller if (touchDetector.begin()) { Serial.println("Touch controller init - OK"); } else { Serial.println("Touch controller init - FAILED"); // Halt execution on failure while (1); } } void loop() { // Touch controller ready for use } ``` -------------------------------- ### Initialize Arduino_GigaDisplayTouch Instance Source: https://context7.com/arduino-libraries/arduino_gigadisplaytouch/llms.txt Demonstrates default and custom constructor usage for the touch controller on supported hardware platforms. ```cpp #include "Arduino_GigaDisplayTouch.h" // Default constructor for Arduino GIGA R1 WiFi // Uses Wire1, default interrupt pin (PI_1), reset pin (PI_2), and I2C address 0x5D Arduino_GigaDisplayTouch touchDetector; // Default constructor for Arduino Portenta H7 // Uses Wire, default interrupt pin (PD_4), reset pin (PD_5), and I2C address 0x5D Arduino_GigaDisplayTouch touchDetector; // Custom constructor with explicit parameters // Parameters: // wire - TwoWire interface (Wire or Wire1) // intPin - Interrupt pin number // rstPin - Reset pin number // addr - I2C address: GT911_I2C_ADDR_BA_BB (0x5D) or GT911_I2C_ADDR_28_29 (0x14) Arduino_GigaDisplayTouch touchDetector(Wire1, pinInterrupt, pinReset, GT911_I2C_ADDR_BA_BB); ``` -------------------------------- ### Arduino_GigaDisplayTouch Constructor Source: https://context7.com/arduino-libraries/arduino_gigadisplaytouch/llms.txt Initializes a new instance of the touch controller. Supports default platform-specific configurations or custom pin and I2C address assignments. ```APIDOC ## Constructor Arduino_GigaDisplayTouch() ### Description Creates a new touch controller instance for the Arduino GIGA Display Shield. Allows for default platform-specific pin configurations or custom hardware setups. ### Parameters - **wire** (TwoWire) - Optional - The I2C interface (e.g., Wire or Wire1). - **intPin** (int) - Optional - The interrupt pin number. - **rstPin** (int) - Optional - The reset pin number. - **addr** (uint8_t) - Optional - The I2C address (GT911_I2C_ADDR_BA_BB or GT911_I2C_ADDR_28_29). ``` -------------------------------- ### LVGL Integration for Touch Input Source: https://context7.com/arduino-libraries/arduino_gigadisplaytouch/llms.txt Initializes the touch detector and LVGL, automatically registering the touch input with LVGL. UI elements will receive touch events without further configuration. Suitable for projects using LVGL. ```cpp #include "Arduino_GigaDisplay_GFX.h" #include "Arduino_GigaDisplayTouch.h" #include "lvgl.h" Arduino_GigaDisplayTouch touchDetector; void setup() { Serial.begin(115200); // Initialize LVGL (display driver setup omitted for brevity) lv_init(); // Initialize touch - automatically registers with LVGL // The library detects LVGL and creates an input device if (touchDetector.begin()) { Serial.println("Touch initialized and registered with LVGL"); } // Create LVGL UI elements - they will receive touch events automatically lv_obj_t* btn = lv_btn_create(lv_scr_act()); lv_obj_set_pos(btn, 100, 100); lv_obj_set_size(btn, 120, 50); lv_obj_t* label = lv_label_create(btn); lv_label_set_text(label, "Touch Me"); lv_obj_center(label); } void loop() { lv_timer_handler(); // LVGL handles touch events internally delay(5); } ``` -------------------------------- ### Constructor: Arduino_GigaDisplayTouch Source: https://github.com/arduino-libraries/arduino_gigadisplaytouch/blob/main/docs/api.md Constructs a new touch controller instance for the Giga Display Shield, specifying the communication interface and pin configurations. ```APIDOC ## Constructor Arduino_GigaDisplayTouch ### Description Construct a new touch controller for Giga Display Shield. ### Parameters * **wire** (TwoWire&) - Required - A reference to the Wire interface to be used for communication with the touch controller. * **intPin** (uint8_t) - Required - The interrupt pin number for the touch controller. * **rstPin** (uint8_t) - Required - The reset pin number for the touch controller. * **addr** (uint8_t) - Required - The device address for the touch controller. ``` -------------------------------- ### Method: end Source: https://github.com/arduino-libraries/arduino_gigadisplaytouch/blob/main/docs/api.md De-initializes the touch controller, releasing resources. ```APIDOC ## Method end ### Description De-initialize the touch controller. ``` -------------------------------- ### Method: onDetect Source: https://github.com/arduino-libraries/arduino_gigadisplaytouch/blob/main/docs/api.md Registers a callback function to be executed when a touch event is detected. ```APIDOC ## Method onDetect ### Description Attach an interrupt handler function for touch detection callbacks. ### Parameters * **handler** (void (*)(uint8_t, GDTpoint_t*)) - Required - The pointer to the user-defined handler function. ``` -------------------------------- ### Polling Touch Detection with getTouchPoints() Source: https://context7.com/arduino-libraries/arduino_gigadisplaytouch/llms.txt Use this method in polling mode to manually check for touch events. It returns the number of contacts and populates an array with touch point data. Ensure the touch controller is initialized before calling. ```cpp #include "Arduino_GigaDisplayTouch.h" Arduino_GigaDisplayTouch touchDetector; void setup() { Serial.begin(115200); while (!Serial) {} if (touchDetector.begin()) { Serial.println("Touch controller init - OK"); } else { Serial.println("Touch controller init - FAILED"); while (1); } } void loop() { uint8_t contacts; GDTpoint_t points[5]; // Array to hold up to 5 touch points // Poll for touch events contacts = touchDetector.getTouchPoints(points); if (contacts > 0) { Serial.print("Contacts: "); Serial.println(contacts); // Iterate through all detected touch points for (uint8_t i = 0; i < contacts; i++) { Serial.print("Point "); Serial.print(i); Serial.print(": X="); Serial.print(points[i].x); Serial.print(" Y="); Serial.print(points[i].y); Serial.print(" TrackID="); Serial.print(points[i].trackId); Serial.print(" Area="); Serial.println(points[i].area); } } delay(1); // Small delay to prevent overwhelming the I2C bus } // Expected Serial Output: // Touch controller init - OK // Contacts: 2 // Point 0: X=412 Y=238 TrackID=0 Area=45 // Point 1: X=156 Y=402 TrackID=1 Area=38 ``` -------------------------------- ### Arduino_GigaDisplayTouch Class Overview Source: https://github.com/arduino-libraries/arduino_gigadisplaytouch/blob/main/docs/api.md The main class for managing the touch controller of the Giga Display Shield. ```APIDOC ## Class Arduino_GigaDisplayTouch The main class for managing the touch controller of the Giga Display Shield. ### Members * `Arduino_GigaDisplayTouch(TwoWire& wire, uint8_t intPin, uint8_t rstPin, uint8_t addr)`: Construct a new touch controller for Giga Display Shield. * `bool begin()`: Initialize the touch controller. * `void end()`: De-initialize the touch controller. * `uint8_t getTouchPoints(GDTpoint_t* points)`: Check if a touch event is detected and get the touch points. * `void onDetect(void (*handler)(uint8_t, GDTpoint_t*))`: Attach an interrupt handler function for touch detection callbacks. ``` -------------------------------- ### Method: getTouchPoints Source: https://github.com/arduino-libraries/arduino_gigadisplaytouch/blob/main/docs/api.md Retrieves the coordinates of detected touch points. ```APIDOC ## Method getTouchPoints ### Description Check if a touch event is detected and get the touch points. ### Parameters * **points** (GDTpoint_t*) - Required - The array containing the coordinates of the touch points. ### Returns * **uint8_t** - The number of detected touch points. ``` -------------------------------- ### De-initialize Touch Controller with end() Source: https://context7.com/arduino-libraries/arduino_gigadisplaytouch/llms.txt Releases resources associated with the touch controller when functionality is no longer required. ```cpp #include "Arduino_GigaDisplayTouch.h" Arduino_GigaDisplayTouch touchDetector; void setup() { Serial.begin(115200); touchDetector.begin(); // Use touch controller... // De-initialize when done touchDetector.end(); } void loop() {} ``` -------------------------------- ### Interrupt Mode Touch Detection with onDetect() Source: https://context7.com/arduino-libraries/arduino_gigadisplaytouch/llms.txt Register a callback function to be automatically invoked when a touch event occurs via hardware interrupt. This is more efficient than polling as it processes touch data only when events happen. The callback receives the number of contacts and touch point data. ```cpp #include "Arduino_GigaDisplayTouch.h" Arduino_GigaDisplayTouch touchDetector; // Callback function invoked on touch events // Parameters: // contacts - Number of touch points detected (1-5) // points - Array of GDTpoint_t structures with touch data void gigaTouchHandler(uint8_t contacts, GDTpoint_t* points) { Serial.print("Contacts: "); Serial.println(contacts); if (contacts > 0) { // Process first touch point Serial.print("First touch: X="); Serial.print(points[0].x); Serial.print(" Y="); Serial.println(points[0].y); // Process all touch points for (uint8_t i = 0; i < contacts; i++) { // Handle multi-touch gestures Serial.print("Touch "); Serial.print(i); Serial.print(": ("); Serial.print(points[i].x); Serial.print(", "); Serial.print(points[i].y); Serial.println(")"); } } } void setup() { Serial.begin(115200); while (!Serial) {} if (touchDetector.begin()) { Serial.println("Touch controller init - OK"); } else { Serial.println("Touch controller init - FAILED"); while (1); } // Register the interrupt callback touchDetector.onDetect(gigaTouchHandler); Serial.println("Touch detection enabled - touch the screen!"); } void loop() { // Main loop is free for other tasks // Touch events are handled automatically via interrupt } // Expected Serial Output: // Touch controller init - OK // Touch detection enabled - touch the screen! // Contacts: 1 // First touch: X=240 Y=320 // Touch 0: (240, 320) ``` -------------------------------- ### onDetect() - Interrupt Mode Touch Detection Source: https://context7.com/arduino-libraries/arduino_gigadisplaytouch/llms.txt Registers a callback function that is automatically invoked when a touch event is detected via hardware interrupt. The callback receives the number of contacts and an array of touch points. This mode is more efficient than polling as it only processes touch data when events occur. ```APIDOC ## onDetect() - Interrupt Mode Touch Detection ### Description Registers a callback function that is automatically invoked when a touch event is detected via hardware interrupt. The callback receives the number of contacts and an array of touch points. This mode is more efficient than polling as it only processes touch data when events occur, freeing the main loop for other tasks. ### Method `void onDetect(void (*callback)(uint8_t contacts, GDTpoint_t* points))` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```cpp #include "Arduino_GigaDisplayTouch.h" Arduino_GigaDisplayTouch touchDetector; // Callback function invoked on touch events // Parameters: // contacts - Number of touch points detected (1-5) // points - Array of GDTpoint_t structures with touch data void gigaTouchHandler(uint8_t contacts, GDTpoint_t* points) { Serial.print("Contacts: "); Serial.println(contacts); if (contacts > 0) { // Process first touch point Serial.print("First touch: X="); Serial.print(points[0].x); Serial.print(" Y="); Serial.println(points[0].y); // Process all touch points for (uint8_t i = 0; i < contacts; i++) { // Handle multi-touch gestures Serial.print("Touch "); Serial.print(i); Serial.print(": ("); Serial.print(points[i].x); Serial.print(", "); Serial.print(points[i].y); Serial.println(")"); } } } void setup() { Serial.begin(115200); while (!Serial) {} if (touchDetector.begin()) { Serial.println("Touch controller init - OK"); } else { Serial.println("Touch controller init - FAILED"); while (1); } // Register the interrupt callback touchDetector.onDetect(gigaTouchHandler); Serial.println("Touch detection enabled - touch the screen!"); } void loop() { // Main loop is free for other tasks // Touch events are handled automatically via interrupt } ``` ### Response #### Success Response (200) This method does not return a value directly. Instead, it registers a callback function that will be executed when a touch event occurs. #### Response Example ``` Touch controller init - OK Touch detection enabled - touch the screen! Contacts: 1 First touch: X=240 Y=320 Touch 0: (240, 320) ``` ``` -------------------------------- ### getTouchPoints() - Polling Mode Touch Detection Source: https://context7.com/arduino-libraries/arduino_gigadisplaytouch/llms.txt Reads the current touch state and returns the number of detected touch points. Touch coordinates are written to the provided GDTpoint_t array. This method is used in polling mode where the application manually checks for touch events. ```APIDOC ## getTouchPoints() - Polling Mode Touch Detection ### Description Reads the current touch state and returns the number of detected touch points (0-5). Touch coordinates are written to the provided GDTpoint_t array. Each touch point contains x and y coordinates, a tracking ID, an area value, and a pressed state. This method is used in polling mode where the application manually checks for touch events. ### Method `uint8_t getTouchPoints(GDTpoint_t points[])` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```cpp #include "Arduino_GigaDisplayTouch.h" Arduino_GigaDisplayTouch touchDetector; void setup() { Serial.begin(115200); while (!Serial) {} if (touchDetector.begin()) { Serial.println("Touch controller init - OK"); } else { Serial.println("Touch controller init - FAILED"); while (1); } } void loop() { uint8_t contacts; GDTpoint_t points[5]; // Array to hold up to 5 touch points // Poll for touch events contacts = touchDetector.getTouchPoints(points); if (contacts > 0) { Serial.print("Contacts: "); Serial.println(contacts); // Iterate through all detected touch points for (uint8_t i = 0; i < contacts; i++) { Serial.print("Point "); Serial.print(i); Serial.print(": X="); Serial.print(points[i].x); Serial.print(" Y="); Serial.print(points[i].y); Serial.print(" TrackID="); Serial.print(points[i].trackId); Serial.print(" Area="); Serial.println(points[i].area); } } delay(1); // Small delay to prevent overwhelming the I2C bus } ``` ### Response #### Success Response (200) Returns the number of detected touch points (0-5). The `GDTpoint_t` array passed as an argument will be populated with touch data. - **contacts** (uint8_t) - The number of touch points detected. - **points** (GDTpoint_t array) - An array containing details for each touch point, including `x`, `y`, `trackId`, and `area`. #### Response Example ``` Contacts: 2 Point 0: X=412 Y=238 TrackID=0 Area=45 Point 1: X=156 Y=402 TrackID=1 Area=38 ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.