-
Notifications
You must be signed in to change notification settings - Fork 3
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
base: main
Are you sure you want to change the base?
Changes from all commits
ab78f0e
e1a53e2
509df52
49e71bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||||
} | ||||
|
||||
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(); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree it is not a |
||||
delay(100); | ||||
touchDetector.onDetect(gigaTouchHandler); | ||||
} | ||||
} |
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); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.I agree, having a
detach()
method would be greatly appreciated 😄 ! See #8