From c5fabcf0ce36bc6676b5977847b85ba88a08e72e Mon Sep 17 00:00:00 2001 From: Ali Jahangiri <75624145+aliphys@users.noreply.github.com> Date: Wed, 12 Jun 2024 16:29:39 +0200 Subject: [PATCH 1/3] feat: add `Section_IRQ.ino` example --- examples/Section_IRQ/Section_IRQ | 87 ++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 examples/Section_IRQ/Section_IRQ diff --git a/examples/Section_IRQ/Section_IRQ b/examples/Section_IRQ/Section_IRQ new file mode 100644 index 0000000..526e1b6 --- /dev/null +++ b/examples/Section_IRQ/Section_IRQ @@ -0,0 +1,87 @@ +/* + * Section_IRQ.ino + * + * This example shows how to use touch screen inputs to control RGB LED states based on different regions of the screen, via interrupts. + * + * Whenever a touch event is detected, gigaTouchHandler() changes the RGB status based on the region touched. + * A millis() based debounce is implemented to prevent multiple touch events. Based on the region touched, the LED status is changed. + * This is also reported over the Serial Monitor. Since the GIGA R1 WiFi RGB LEDs are active low (common annode), + * the LED status is inverted. + * + * For the polling version of this example, see Section_Polling.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) and change the LED status on the GIGA R1 WiFi. + * | Screen section | LED | + * |----------------|-------| + * | Left third | Red | + * | Middle third | Green | + * | Right third | Blue | + * + * Initial author: Ali Jahangiri @aliphys + * Created: 12 June 2024 + */ + +#include "Arduino_GigaDisplayTouch.h" + +Arduino_GigaDisplayTouch touchDetector; + +bool LEDRed = false; +bool LEDGreen = false; +bool LEDBlue = false; + +unsigned long last_touch_time = 0; + +void gigaTouchHandler(uint8_t contacts, GDTpoint_t* points) { + unsigned long touch_time = millis(); + + if (touch_time - last_touch_time > 300) { // debounce + // right third of the screen + if (points[0].y > 520) { + LEDBlue = !LEDBlue; + digitalWrite(LEDB, LEDBlue); + Serial.print("Blue LED State Changed: "); + Serial.println(!LEDBlue); + } + // middle third of the screen + else if (points[0].y > 260) { + LEDGreen = !LEDGreen; + digitalWrite(LEDG, LEDGreen); + Serial.print("Green LED State Changed: "); + Serial.println(!LEDGreen); + } + // left third of the screen + else { + LEDRed = !LEDRed; + digitalWrite(LEDR, LEDRed); + Serial.print("Red LED State Changed: "); + Serial.println(!LEDRed); + } + } + + last_touch_time = touch_time; + +} + +void setup() { + pinMode(LEDR, OUTPUT); + pinMode(LEDG, OUTPUT); + pinMode(LEDB, OUTPUT); + + 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() {} \ No newline at end of file From 21ae780eabad8796ec40f695013f67c23ce142b1 Mon Sep 17 00:00:00 2001 From: Ali Jahangiri <75624145+aliphys@users.noreply.github.com> Date: Wed, 12 Jun 2024 16:29:48 +0200 Subject: [PATCH 2/3] feat: add `Section_Polling.ino` example --- examples/Section_Polling/Section_Polling.ino | 89 ++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 examples/Section_Polling/Section_Polling.ino diff --git a/examples/Section_Polling/Section_Polling.ino b/examples/Section_Polling/Section_Polling.ino new file mode 100644 index 0000000..628ce82 --- /dev/null +++ b/examples/Section_Polling/Section_Polling.ino @@ -0,0 +1,89 @@ +/* + * Section_Polling.ino + * + * This example shows how to use touch screen inputs to control RGB LED states based on different regions of the screen, via polling. + * + * The loop() function continuously checks to see if a touch event is detected. + * A millis() based debounce is implemented to prevent multiple touch events. Based on the region touched, the LED status is changed. + * This is also reported over the Serial Monitor. Since the GIGA R1 WiFi RGB LEDs are active low (common annode), + * the LED status is inverted. + * + * For the interrupt version of this example, see Section_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) and change the LED status on the GIGA R1 WiFi. + * | Screen section | LED | + * |----------------|-------| + * | Left third | Red | + * | Middle third | Green | + * | Right third | Blue | + * + * Initial author: Ali Jahangiri @aliphys + * Created: 12 June 2024 + */ + +#include "Arduino_GigaDisplayTouch.h" + +Arduino_GigaDisplayTouch touchDetector; + +bool LEDRed = false; +bool LEDGreen = false; +bool LEDBlue = false; + +unsigned long last_touch_time = 0; + +void setup() { + pinMode(LEDR, OUTPUT); + pinMode(LEDG, OUTPUT); + pinMode(LEDB, OUTPUT); + + 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]; + + contacts = touchDetector.getTouchPoints(points); + + unsigned long touch_time = millis(); + if (contacts > 0 && touch_time - last_touch_time > 300) { + // right third of the screen + if (points[0].y > 520) { + LEDBlue = !LEDBlue; + digitalWrite(LEDB, LEDBlue); + Serial.print("Blue LED State Changed: "); + Serial.println(!LEDBlue); + } + // middle third of the screen + else if (points[0].y > 260) { + LEDGreen = !LEDGreen; + digitalWrite(LEDG, LEDGreen); + Serial.print("Green LED State Changed: "); + Serial.println(!LEDGreen); + } + // left third of the screen + else { + LEDRed = !LEDRed; + digitalWrite(LEDR, LEDRed); + Serial.print("Red LED State Changed: "); + Serial.println(!LEDRed); + } + + last_touch_time = touch_time; + } + + delay(1); +} \ No newline at end of file From 8da8f9a89e2f87e62ef45537fbf0cc3336baf763 Mon Sep 17 00:00:00 2001 From: Ali Jahangiri <75624145+aliphys@users.noreply.github.com> Date: Wed, 12 Jun 2024 19:48:20 +0200 Subject: [PATCH 3/3] fix: append `.ino` to filenmae --- examples/Section_IRQ/{Section_IRQ => Section_IRQ.ino} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/Section_IRQ/{Section_IRQ => Section_IRQ.ino} (100%) diff --git a/examples/Section_IRQ/Section_IRQ b/examples/Section_IRQ/Section_IRQ.ino similarity index 100% rename from examples/Section_IRQ/Section_IRQ rename to examples/Section_IRQ/Section_IRQ.ino