Skip to content

Add MultiTouchBlink examples #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions examples/MultiTouchBlink_IRQ/MultiTouchBlink_IRQ.ino
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
touchDetector.end(); // close the touch controller
touchDetector.detach();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not see a member function for .detach() in the Arduino_GigaDisplayTouch.h header. When making the change recommended the following error is given.

C:\GitHub\Arduino\Arduino_GigaDisplayTouch\examples\MultiTouchBlink_IRQ\MultiTouchBlink_IRQ.ino:30:17: error: 'class Arduino_GigaDisplayTouch' has no member named 'detach'
   touchDetector.detach();  // close the touch controller
                 ^~~~~~

Using library Arduino_GigaDisplayTouch at version 1.0.1 in folder: C:\Users\Ali Jahangiri\Documents\Arduino\libraries\Arduino_GigaDisplayTouch 
Using library Wire in folder: C:\Users\Ali Jahangiri\AppData\Local\Arduino15\packages\arduino\hardware\mbed_giga\4.1.3\libraries\Wire (legacy)
exit status 1

Compilation error: 'class Arduino_GigaDisplayTouch' has no member named 'detach'

I agree, having a detach() method would be greatly appreciated 😄 ! See #8

}

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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
touchDetector.begin();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it is not a pretty solution, but it works. One should not use begin() in the middle of a sketch to restart the GT911 module. See: #11 (comment)

delay(100);
touchDetector.onDetect(gigaTouchHandler);
}
}
61 changes: 61 additions & 0 deletions examples/MultiTouchBlink_Polling/MultiTouchBlink_Polling.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* 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);
}
Loading