Skip to content

Commit 21ae780

Browse files
committed
feat: add Section_Polling.ino example
1 parent c5fabcf commit 21ae780

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Section_Polling.ino
3+
*
4+
* This example shows how to use touch screen inputs to control RGB LED states based on different regions of the screen, via polling.
5+
*
6+
* The loop() function continuously checks to see if a touch event is detected.
7+
* A millis() based debounce is implemented to prevent multiple touch events. Based on the region touched, the LED status is changed.
8+
* This is also reported over the Serial Monitor. Since the GIGA R1 WiFi RGB LEDs are active low (common annode),
9+
* the LED status is inverted.
10+
*
11+
* For the interrupt version of this example, see Section_IRQ.ino
12+
*
13+
* Instructions:
14+
* 1. Connect your GIGA Display Shield (ASX00039) to a GIGA R1 WiFi (ABX00063) board.
15+
* 2. Upload this sketch to your board.
16+
* 3. Open the Serial Monitor.
17+
* 4. Touch the screen with your finger(s) and change the LED status on the GIGA R1 WiFi.
18+
* | Screen section | LED |
19+
* |----------------|-------|
20+
* | Left third | Red |
21+
* | Middle third | Green |
22+
* | Right third | Blue |
23+
*
24+
* Initial author: Ali Jahangiri @aliphys
25+
* Created: 12 June 2024
26+
*/
27+
28+
#include "Arduino_GigaDisplayTouch.h"
29+
30+
Arduino_GigaDisplayTouch touchDetector;
31+
32+
bool LEDRed = false;
33+
bool LEDGreen = false;
34+
bool LEDBlue = false;
35+
36+
unsigned long last_touch_time = 0;
37+
38+
void setup() {
39+
pinMode(LEDR, OUTPUT);
40+
pinMode(LEDG, OUTPUT);
41+
pinMode(LEDB, OUTPUT);
42+
43+
Serial.begin(115200);
44+
while (!Serial) {}
45+
46+
if (touchDetector.begin()) {
47+
Serial.println("Touch controller init - OK");
48+
} else {
49+
Serial.println("Touch controller init - FAILED");
50+
while (1);
51+
}
52+
}
53+
54+
55+
void loop() {
56+
uint8_t contacts;
57+
GDTpoint_t points[5];
58+
59+
contacts = touchDetector.getTouchPoints(points);
60+
61+
unsigned long touch_time = millis();
62+
if (contacts > 0 && touch_time - last_touch_time > 300) {
63+
// right third of the screen
64+
if (points[0].y > 520) {
65+
LEDBlue = !LEDBlue;
66+
digitalWrite(LEDB, LEDBlue);
67+
Serial.print("Blue LED State Changed: ");
68+
Serial.println(!LEDBlue);
69+
}
70+
// middle third of the screen
71+
else if (points[0].y > 260) {
72+
LEDGreen = !LEDGreen;
73+
digitalWrite(LEDG, LEDGreen);
74+
Serial.print("Green LED State Changed: ");
75+
Serial.println(!LEDGreen);
76+
}
77+
// left third of the screen
78+
else {
79+
LEDRed = !LEDRed;
80+
digitalWrite(LEDR, LEDRed);
81+
Serial.print("Red LED State Changed: ");
82+
Serial.println(!LEDRed);
83+
}
84+
85+
last_touch_time = touch_time;
86+
}
87+
88+
delay(1);
89+
}

0 commit comments

Comments
 (0)