From ab78f0e3f705bc2e51b6d538f6ee258ab82835ec Mon Sep 17 00:00:00 2001 From: Ali Jahangiri <75624145+aliphys@users.noreply.github.com> Date: Thu, 13 Jun 2024 10:51:06 +0200 Subject: [PATCH 1/4] feat: add MultiTouch Interrupt example --- .../MultiTouchBlink_IRQ.ino | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 examples/MultiTouchBlink_IRQ/MultiTouchBlink_IRQ.ino diff --git a/examples/MultiTouchBlink_IRQ/MultiTouchBlink_IRQ.ino b/examples/MultiTouchBlink_IRQ/MultiTouchBlink_IRQ.ino new file mode 100644 index 0000000..e223b63 --- /dev/null +++ b/examples/MultiTouchBlink_IRQ/MultiTouchBlink_IRQ.ino @@ -0,0 +1,61 @@ +/* + * MultiTouchBlink_IRQ.ino + * + * This example shows how to visualise the number of touch points, using the RGB LED. + * + * Whenever a touch event is detected, gigaTouchHandler() records the number of touches and blinks the RGB LED accordingly. + * The event is also detected and sent via Serial. The touch handler is detached, blink is performed and then re-attached. + * + * For the polling version of this example, see MultiTouchBlink_IRQ.ino + * + * Instructions: + * 1. Connect your GIGA Display Shield (ASX00039) to a GIGA R1 WiFi (ABX00063) board. + * 2. Upload this sketch to your board. + * 3. Open the Serial Monitor. + * 4. Touch the screen with your finger(s). + * 5. The LED will blink, based on how many touch contact are recorded. Note that fingers need to be placed all at the same time. + * + * Initial author: Ali Jahangiri @aliphys + * Created: 12 June 2024 + */ + +#include "Arduino_GigaDisplayTouch.h" + +Arduino_GigaDisplayTouch touchDetector; + +int contactPoints = 0; + +void gigaTouchHandler(uint8_t contacts, GDTpoint_t* points) { + contactPoints = contacts; + touchDetector.end(); // close the touch controller +} + +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); + } + + touchDetector.onDetect(gigaTouchHandler); +} + +void loop() { + if (contactPoints > 0) { + Serial.println("Contact Detected! Will Blink " + String(contactPoints) + " times!"); + for (int i = 0; i < contactPoints; i++) { + digitalWrite(LED_BUILTIN, LOW); + delay(250); + digitalWrite(LED_BUILTIN, HIGH); + delay(250); + } + contactPoints = 0; + touchDetector.begin(); + delay(100); + touchDetector.onDetect(gigaTouchHandler); + } +} \ No newline at end of file From e1a53e2e68755a239559b27cf8eb17ad06acb648 Mon Sep 17 00:00:00 2001 From: Ali Jahangiri <75624145+aliphys@users.noreply.github.com> Date: Thu, 13 Jun 2024 10:51:13 +0200 Subject: [PATCH 2/4] feat: add MultiTouch Polling example --- .../MultiTouchBlink_Polling.ino | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 examples/MultiTouchBlink_Polling/MultiTouchBlink_Polling.ino diff --git a/examples/MultiTouchBlink_Polling/MultiTouchBlink_Polling.ino b/examples/MultiTouchBlink_Polling/MultiTouchBlink_Polling.ino new file mode 100644 index 0000000..0a87eb0 --- /dev/null +++ b/examples/MultiTouchBlink_Polling/MultiTouchBlink_Polling.ino @@ -0,0 +1,62 @@ +/* + * MultiTouchBlink_Polling.ino + * + * This example shows how to visualise the number of touch points, using the RGB LED. + * + * On each iteration of the loop, the touch points are obtained from the GT911 controller. If the touch points exist, then a message + * is sent to the Serial, and the LED is blinked the corresponding number of times. A 1 second delay is given after a touch is detected, to + * act as a basic debounce utility. + * + * For the interrupt version of this example, see MultiTouchBlink_IRQ.ino + * + * Instructions: + * 1. Connect your GIGA Display Shield (ASX00039) to a GIGA R1 WiFi (ABX00063) board. + * 2. Upload this sketch to your board. + * 3. Open the Serial Monitor. + * 4. Touch the screen with your finger(s). + * 5. The LED will blink, based on how many touch contact are recorded. Note that fingers need to be placed all at the same time. + * + * Initial author: Ali Jahangiri @aliphys + * Created: 12 June 2024 + */ + +#include "Arduino_GigaDisplayTouch.h" + +Arduino_GigaDisplayTouch touchDetector; + +int contactPoints = 0; + +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]; + contactPoints = 0; + + contactPoints = touchDetector.getTouchPoints(points); + + if (contactPoints > 0) { + Serial.println("Contact Detected! Will Blink " + String(contactPoints) + " times!"); + for (int i = 1; i <= contactPoints; i++) { + digitalWrite(LED_BUILTIN, LOW); + delay(250); + digitalWrite(LED_BUILTIN, HIGH); + delay(250); + } + + delay(1000); + } + + delay(1); +} \ No newline at end of file From 509df526021cfddc6caab30f415894aeb542a224 Mon Sep 17 00:00:00 2001 From: Ali Jahangiri <75624145+aliphys@users.noreply.github.com> Date: Thu, 13 Jun 2024 11:52:10 +0200 Subject: [PATCH 3/4] Update examples/MultiTouchBlink_Polling/MultiTouchBlink_Polling.ino Co-authored-by: Leonardo Cavagnis <45899760+leonardocavagnis@users.noreply.github.com> --- examples/MultiTouchBlink_Polling/MultiTouchBlink_Polling.ino | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/MultiTouchBlink_Polling/MultiTouchBlink_Polling.ino b/examples/MultiTouchBlink_Polling/MultiTouchBlink_Polling.ino index 0a87eb0..7a48d22 100644 --- a/examples/MultiTouchBlink_Polling/MultiTouchBlink_Polling.ino +++ b/examples/MultiTouchBlink_Polling/MultiTouchBlink_Polling.ino @@ -35,7 +35,6 @@ void setup() { } else { Serial.println("Touch controller init - FAILED"); while (1) - ; } } From 49e71bc54f4bb16094ea3b5d77b20f575496db69 Mon Sep 17 00:00:00 2001 From: Ali Jahangiri <75624145+aliphys@users.noreply.github.com> Date: Thu, 13 Jun 2024 11:52:17 +0200 Subject: [PATCH 4/4] Update examples/MultiTouchBlink_Polling/MultiTouchBlink_Polling.ino Co-authored-by: Leonardo Cavagnis <45899760+leonardocavagnis@users.noreply.github.com> --- examples/MultiTouchBlink_Polling/MultiTouchBlink_Polling.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/MultiTouchBlink_Polling/MultiTouchBlink_Polling.ino b/examples/MultiTouchBlink_Polling/MultiTouchBlink_Polling.ino index 7a48d22..cabe0b5 100644 --- a/examples/MultiTouchBlink_Polling/MultiTouchBlink_Polling.ino +++ b/examples/MultiTouchBlink_Polling/MultiTouchBlink_Polling.ino @@ -34,7 +34,7 @@ void setup() { Serial.println("Touch controller init - OK"); } else { Serial.println("Touch controller init - FAILED"); - while (1) + while (1) ; } }