1
+ /*
2
+ * Section_IRQ.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 interrupts.
5
+ *
6
+ * Whenever a touch event is detected, gigaTouchHandler() changes the RGB status based on the region touched.
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 polling version of this example, see Section_Polling.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 gigaTouchHandler(uint8_t contacts, GDTpoint_t* points) {
39
+ unsigned long touch_time = millis();
40
+
41
+ if (touch_time - last_touch_time > 300) { // debounce
42
+ // right third of the screen
43
+ if (points[0].y > 520) {
44
+ LEDBlue = !LEDBlue;
45
+ digitalWrite(LEDB, LEDBlue);
46
+ Serial.print("Blue LED State Changed: ");
47
+ Serial.println(!LEDBlue);
48
+ }
49
+ // middle third of the screen
50
+ else if (points[0].y > 260) {
51
+ LEDGreen = !LEDGreen;
52
+ digitalWrite(LEDG, LEDGreen);
53
+ Serial.print("Green LED State Changed: ");
54
+ Serial.println(!LEDGreen);
55
+ }
56
+ // left third of the screen
57
+ else {
58
+ LEDRed = !LEDRed;
59
+ digitalWrite(LEDR, LEDRed);
60
+ Serial.print("Red LED State Changed: ");
61
+ Serial.println(!LEDRed);
62
+ }
63
+ }
64
+
65
+ last_touch_time = touch_time;
66
+
67
+ }
68
+
69
+ void setup() {
70
+ pinMode(LEDR, OUTPUT);
71
+ pinMode(LEDG, OUTPUT);
72
+ pinMode(LEDB, OUTPUT);
73
+
74
+ Serial.begin(115200);
75
+ while(!Serial) {}
76
+
77
+ if (touchDetector.begin()) {
78
+ Serial.println("Touch controller init - OK");
79
+ } else {
80
+ Serial.println("Touch controller init - FAILED");
81
+ while(1);
82
+ }
83
+
84
+ touchDetector.onDetect(gigaTouchHandler);
85
+ }
86
+
87
+ void loop() {}
0 commit comments