### Start and Configure Touch Controller Source: https://context7.com/strange-v/ft6x36/llms.txt Initializes the I2C communication and the touch controller hardware. The begin() method verifies the chip ID and sets the sensitivity threshold for touch detection. ```cpp #include #include #include FT6X36 ts(&Wire, 15); void setup() { Serial.begin(115200); Wire.begin(); if (ts.begin()) { Serial.println("Touch controller initialized successfully"); } else { Serial.println("Touch controller not found!"); } } void loop() { ts.loop(); } ``` -------------------------------- ### Initialize FT6X36 Controller Instance Source: https://context7.com/strange-v/ft6x36/llms.txt Demonstrates how to instantiate the FT6X36 class by specifying the I2C bus and the hardware interrupt pin. This setup is required before calling any initialization methods. ```cpp #include #include #include // Create touch controller on Wire bus with interrupt on GPIO 15 FT6X36 ts(&Wire, 15); // Alternative: Use Wire1 bus on ESP32 with interrupt on GPIO 4 FT6X36 ts2(&Wire1, 4); ``` -------------------------------- ### Process Touch Events with FreeRTOS Tasks (Arduino C++) Source: https://context7.com/strange-v/ft6x36/llms.txt This example demonstrates a more advanced approach using FreeRTOS tasks to process touch events. The `processTouch()` method is called directly within a dedicated task, triggered by an ISR. This provides more granular control and is ideal for complex, real-time applications. ```cpp #include #include #include #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "freertos/event_groups.h" #define TOUCH_EVENT (1 << 0) #define BUTTON_EVENT (1 << 1) EventGroupHandle_t eg; FT6X36 ts(&Wire, 15); void TouchTask(void *pvParameters) { for (;;) { xEventGroupWaitBits(eg, TOUCH_EVENT, pdTRUE, pdTRUE, portMAX_DELAY); ts.processTouch(); // Directly process touch data } } void ButtonTask(void *pvParameters) { for (;;) { xEventGroupWaitBits(eg, BUTTON_EVENT, pdTRUE, pdTRUE, portMAX_DELAY); Serial.println("Virtual button pressed!"); } } void IRAM_ATTR isr() { BaseType_t xHigherPriorityTaskWoken; xEventGroupSetBitsFromISR(eg, TOUCH_EVENT, &xHigherPriorityTaskWoken); } void handleTouch(TPoint p, TEvent e) { if (e != TEvent::Tap) return; // Create virtual button in top-left corner (50x50 pixels) if (p.x < 50 && p.y < 50) { xEventGroupSetBits(eg, BUTTON_EVENT); } Serial.printf("Touch at x: %d, y: %d\n", p.x, p.y); } void setup() { Serial.begin(115200); Wire.begin(21, 22, 400000U); eg = xEventGroupCreate(); ts.begin(); ts.registerIsrHandler(isr); ts.registerTouchHandler(handleTouch); xTaskCreatePinnedToCore(TouchTask, "TouchTask", 10000, NULL, 3, NULL, 1); xTaskCreatePinnedToCore(ButtonTask, "ButtonTask", 10000, NULL, 3, NULL, 1); } void loop() {} ``` -------------------------------- ### TEvent Enumeration for Touch Event Types (Arduino C++) Source: https://context7.com/strange-v/ft6x36/llms.txt This code defines the `TEvent` enumeration, which categorizes different types of touch interactions detected by the library. It distinguishes between basic touch events (start, move, end) and more complex gestures like taps and drags. The example shows how to use a switch statement to handle specific event types. ```cpp enum class TEvent { None, // No event TouchStart, // Finger first touches screen TouchMove, // Finger moves while touching TouchEnd, // Finger lifts from screen Tap, // Quick touch and release (< 300ms, minimal movement) DragStart, // Long press starts (> 300ms at same position) DragMove, // Movement during drag operation DragEnd // Finger lifts after dragging }; // Example: Filter for specific events void handleTouch(TPoint p, TEvent e) { // Only respond to taps and drags, ignore raw touch events if (e != TEvent::Tap && e != TEvent::DragStart && e != TEvent::DragMove && e != TEvent::DragEnd) { return; } switch (e) { case TEvent::Tap: Serial.printf("TAP at (%d, %d)\n", p.x, p.y); break; case TEvent::DragStart: Serial.printf("DRAG START at (%d, %d)\n", p.x, p.y); break; case TEvent::DragMove: Serial.printf("DRAG MOVE to (%d, %d)\n", p.x, p.y); break; case TEvent::DragEnd: Serial.printf("DRAG END at (%d, %d)\n", p.x, p.y); break; default: break; } } ``` -------------------------------- ### TPoint Structure Definition and Usage (C++) Source: https://context7.com/strange-v/ft6x36/llms.txt Defines the TPoint structure to represent touch coordinates (x, y) and includes an `aboutEqual` method for comparing points with a small tolerance. An example demonstrates its use in a touch event handler for detecting taps near a specific region. ```cpp struct TPoint { uint16_t x; uint16_t y; bool aboutEqual(const TPoint point) { const uint8_t maxDeviation = 5; return abs(x - point.x) <= maxDeviation && abs(y - point.y) <= maxDeviation; } }; // Example: Using TPoint in touch handler void handleTouch(TPoint p, TEvent e) { // Define button regions TPoint buttonCenter = {100, 100}; if (e == TEvent::Tap) { // Check if tap is near button (within 5 pixels) if (p.aboutEqual(buttonCenter)) { Serial.println("Button tapped!"); } // Manual region check for larger areas if (p.x >= 50 && p.x <= 150 && p.y >= 50 && p.y <= 150) { Serial.println("Tapped within 100x100 region"); } } } ``` -------------------------------- ### touched() - Get Number of Touches Source: https://context7.com/strange-v/ft6x36/llms.txt Returns the number of current touch points detected (0, 1, or 2). This method directly queries the touch controller's register for the number of active touches. ```APIDOC ## touched Returns the number of current touch points detected (0, 1, or 2). This method directly queries the touch controller's register for the number of active touches. ### Method `FT6X36::touched()` ### Endpoint N/A (This is a method call) ### Parameters None ### Request Example ```cpp #include #include #include FT6X36 ts(&Wire, 15); void setup() { Serial.begin(115200); Wire.begin(); ts.begin(); } void loop() { uint8_t numTouches = ts.touched(); if (numTouches > 0) { Serial.print("Number of touches: "); Serial.println(numTouches); } ts.loop(); delay(50); } ``` ### Response #### Success Response (200) - **numTouches** (uint8_t) - The number of currently detected touch points (0, 1, or 2). ### Response Example ``` Number of touches: 1 ``` ``` -------------------------------- ### Get Number of Touches Detected (Arduino C++) Source: https://context7.com/strange-v/ft6x36/llms.txt This code snippet demonstrates how to retrieve the current number of active touch points on the screen using the `touched()` method. It queries the touch controller directly and returns a value of 0, 1, or 2. This is useful for applications that need to know how many fingers are interacting with the screen. ```cpp #include #include #include FT6X36 ts(&Wire, 15); void setup() { Serial.begin(115200); Wire.begin(); ts.begin(); } void loop() { uint8_t numTouches = ts.touched(); if (numTouches > 0) { Serial.print("Number of touches: "); Serial.println(numTouches); } ts.loop(); delay(50); } ``` -------------------------------- ### FT6X36 Configuration Constants (C++) Source: https://context7.com/strange-v/ft6x36/llms.txt Provides essential preprocessor definitions for configuring the FT6X36 touch controller library. This includes I2C addresses, supported chip IDs, power modes, and touch sensitivity thresholds. ```cpp // I2C Address #define FT6X36_ADDR 0x38 // Supported Chip IDs #define FT6206_CHIPID 0x06 #define FT6236_CHIPID 0x36 #define FT6336_CHIPID 0x64 // Power Modes #define FT6X36_PMODE_ACTIVE 0x00 // Normal operation #define FT6X36_PMODE_MONITOR 0x01 // Low power monitoring #define FT6X36_PMODE_STANDBY 0x02 // Standby mode #define FT6X36_PMODE_HIBERNATE 0x03 // Hibernate mode // Default touch threshold (0-255, lower = more sensitive) #define FT6X36_DEFAULT_THRESHOLD 22 // Enable debug output (uncomment in FT6X36.h) // #define FT6X36_DEBUG 1 // #define I2C_DEBUG 1 ``` -------------------------------- ### Register Touch Event Callback Source: https://context7.com/strange-v/ft6x36/llms.txt Sets up a callback function to handle various touch events like taps, drags, and movement. The callback receives a TPoint struct containing coordinates and a TEvent enum indicating the action type. ```cpp #include #include #include FT6X36 ts(&Wire, 15); void handleTouch(TPoint point, TEvent event) { Serial.print("X: "); Serial.print(point.x); Serial.print(", Y: "); Serial.print(point.y); Serial.print(" - Event: "); switch (event) { case TEvent::TouchStart: Serial.println("TouchStart"); break; case TEvent::Tap: Serial.println("Tap"); break; case TEvent::DragStart: Serial.println("DragStart"); break; default: Serial.println("Other"); break; } } void setup() { Serial.begin(115200); Wire.begin(); ts.begin(); ts.registerTouchHandler(handleTouch); } void loop() { ts.loop(); } ``` -------------------------------- ### processTouch() - FreeRTOS Task Integration Source: https://context7.com/strange-v/ft6x36/llms.txt Directly processes a single touch event by reading data from the controller and firing appropriate callbacks. Use this method in FreeRTOS task-based architectures instead of `loop()` for more granular control over when touch processing occurs. ```APIDOC ## processTouch Directly processes a single touch event by reading data from the controller and firing appropriate callbacks. Use this method in FreeRTOS task-based architectures instead of `loop()` for more granular control over when touch processing occurs. ### Method `FT6X36::processTouch()` ### Endpoint N/A (This is a method call within a FreeRTOS task) ### Parameters None ### Request Example ```cpp #include #include #include #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "freertos/event_groups.h" #define TOUCH_EVENT (1 << 0) #define BUTTON_EVENT (1 << 1) EventGroupHandle_t eg; FT6X36 ts(&Wire, 15); void TouchTask(void *pvParameters) { for (;;) { xEventGroupWaitBits(eg, TOUCH_EVENT, pdTRUE, pdTRUE, portMAX_DELAY); ts.processTouch(); // Directly process touch data } } void ButtonTask(void *pvParameters) { for (;;) { xEventGroupWaitBits(eg, BUTTON_EVENT, pdTRUE, pdTRUE, portMAX_DELAY); Serial.println("Virtual button pressed!"); } } void IRAM_ATTR isr() { BaseType_t xHigherPriorityTaskWoken; xEventGroupSetBitsFromISR(eg, TOUCH_EVENT, &xHigherPriorityTaskWoken); } void handleTouch(TPoint p, TEvent e) { if (e != TEvent::Tap) return; // Create virtual button in top-left corner (50x50 pixels) if (p.x < 50 && p.y < 50) { xEventGroupSetBits(eg, BUTTON_EVENT); } Serial.printf("Touch at x: %d, y: %d\n", p.x, p.y); } void setup() { Serial.begin(115200); Wire.begin(21, 22, 400000U); eg = xEventGroupCreate(); ts.begin(); ts.registerIsrHandler(isr); ts.registerTouchHandler(handleTouch); xTaskCreatePinnedToCore(TouchTask, "TouchTask", 10000, NULL, 3, NULL, 1); xTaskCreatePinnedToCore(ButtonTask, "ButtonTask", 10000, NULL, 3, NULL, 1); } void loop() {} ``` ### Response N/A (This method modifies internal state and triggers callbacks) ### Response Example N/A ``` -------------------------------- ### Constants and Configuration Source: https://context7.com/strange-v/ft6x36/llms.txt Library constants for I2C communication, chip identification, and power management modes. ```APIDOC ## FT6X36 Configuration Constants ### Description Definitions for I2C addresses, supported chip IDs, and power management modes for the FT6X36 controller. ### Constants - **FT6X36_ADDR** (0x38) - Default I2C address - **Chip IDs** - FT6206 (0x06), FT6236 (0x36), FT6336 (0x64) - **Power Modes** - ACTIVE (0x00), MONITOR (0x01), STANDBY (0x02), HIBERNATE (0x03) - **FT6X36_DEFAULT_THRESHOLD** (22) - Default sensitivity threshold (0-255) ``` -------------------------------- ### loop() - Standard Arduino Loop Source: https://context7.com/strange-v/ft6x36/llms.txt Processes pending touch interrupts by checking the interrupt counter and calling `processTouch()` for each pending event. This should be called regularly in the main `loop()` function when not using a custom FreeRTOS task-based approach. ```APIDOC ## loop Processes pending touch interrupts by checking the interrupt counter and calling `processTouch()` for each pending event. Must be called regularly in the main `loop()` function when not using a custom FreeRTOS task-based approach. ### Method Implicitly called by the Arduino framework. ### Endpoint N/A (This is a function within the Arduino `loop` context) ### Parameters None ### Request Example ```cpp #include #include #include FT6X36 ts(&Wire, 15); void handleTouch(TPoint p, TEvent e) { if (e == TEvent::Tap) { Serial.printf("Tapped at (%d, %d)\n", p.x, p.y); } } void setup() { Serial.begin(115200); Wire.begin(); ts.begin(); ts.registerTouchHandler(handleTouch); } void loop() { // Process any pending touch events ts.loop(); // Other application logic delay(10); } ``` ### Response N/A (This function modifies internal state and triggers callbacks) ### Response Example N/A ``` -------------------------------- ### Configure Custom Interrupt Service Routine Source: https://context7.com/strange-v/ft6x36/llms.txt Allows registration of a custom ISR for advanced use cases like FreeRTOS task synchronization. This is useful for offloading touch processing from the main loop to a dedicated background task. ```cpp #include #include #include #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "freertos/event_groups.h" EventGroupHandle_t eventGroup; FT6X36 ts(&Wire, 15); void IRAM_ATTR customIsr() { BaseType_t xHigherPriorityTaskWoken; xEventGroupSetBitsFromISR(eventGroup, (1 << 0), &xHigherPriorityTaskWoken); } void touchProcessingTask(void *pvParameters) { for (;;) { xEventGroupWaitBits(eventGroup, (1 << 0), pdTRUE, pdTRUE, portMAX_DELAY); ts.processTouch(); } } void setup() { eventGroup = xEventGroupCreate(); ts.begin(); ts.registerIsrHandler(customIsr); xTaskCreatePinnedToCore(touchProcessingTask, "TouchTask", 10000, NULL, 3, NULL, 1); } ``` -------------------------------- ### TEvent Enumeration - Touch Event Types Source: https://context7.com/strange-v/ft6x36/llms.txt Defines the types of touch events that can be detected. The library automatically distinguishes between taps (quick touch and release) and drags (touch held for more than 300ms or moved significantly). ```APIDOC ## TEvent Enumeration Defines the types of touch events that can be detected. The library automatically distinguishes between taps (quick touch and release) and drags (touch held for more than 300ms or moved significantly). ### Enum Values - **TEvent::None**: No event - **TEvent::TouchStart**: Finger first touches screen - **TEvent::TouchMove**: Finger moves while touching - **TEvent::TouchEnd**: Finger lifts from screen - **TEvent::Tap**: Quick touch and release (< 300ms, minimal movement) - **TEvent::DragStart**: Long press starts (> 300ms at same position) - **TEvent::DragMove**: Movement during drag operation - **TEvent::DragEnd**: Finger lifts after dragging ### Example Usage ```cpp enum class TEvent { None, TouchStart, TouchMove, TouchEnd, Tap, DragStart, DragMove, DragEnd }; // Example: Filter for specific events void handleTouch(TPoint p, TEvent e) { // Only respond to taps and drags, ignore raw touch events if (e != TEvent::Tap && e != TEvent::DragStart && e != TEvent::DragMove && e != TEvent::DragEnd) { return; } switch (e) { case TEvent::Tap: Serial.printf("TAP at (%d, %d)\n", p.x, p.y); break; case TEvent::DragStart: Serial.printf("DRAG START at (%d, %d)\n", p.x, p.y); break; case TEvent::DragMove: Serial.printf("DRAG MOVE to (%d, %d)\n", p.x, p.y); break; case TEvent::DragEnd: Serial.printf("DRAG END at (%d, %d)\n", p.x, p.y); break; default: break; } } ``` ``` -------------------------------- ### Process Touch Interrupts in Main Loop (Arduino C++) Source: https://context7.com/strange-v/ft6x36/llms.txt This snippet shows how to process pending touch interrupts within the main Arduino loop function. It relies on the ts.loop() method to check for and handle touch events. This is suitable for simpler applications where a dedicated FreeRTOS task is not required. ```cpp #include #include #include FT6X36 ts(&Wire, 15); void handleTouch(TPoint p, TEvent e) { if (e == TEvent::Tap) { Serial.printf("Tapped at (%d, %d)\n", p.x, p.y); } } void setup() { Serial.begin(115200); Wire.begin(); ts.begin(); ts.registerTouchHandler(handleTouch); } void loop() { // Process any pending touch events ts.loop(); // Other application logic delay(10); } ``` -------------------------------- ### TPoint Data Structure Source: https://context7.com/strange-v/ft6x36/llms.txt The TPoint structure is used to represent touch coordinates and provides built-in comparison logic for touch detection. ```APIDOC ## TPoint Structure ### Description Represents a touch point with x and y coordinates. Includes an `aboutEqual()` method for comparing positions with a tolerance of 5 pixels. ### Structure Definition - **x** (uint16_t) - X coordinate of the touch point - **y** (uint16_t) - Y coordinate of the touch point ### Methods - **aboutEqual(TPoint point)** - Returns true if the distance between the current point and the provided point is within 5 pixels. ### Example Usage ```cpp TPoint p = {100, 100}; TPoint target = {102, 98}; if (p.aboutEqual(target)) { // Returns true } ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.