Skip to content

Add Section RGB examples #12

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 3 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
87 changes: 87 additions & 0 deletions examples/Section_IRQ/Section_IRQ.ino
Original file line number Diff line number Diff line change
@@ -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() {}
89 changes: 89 additions & 0 deletions examples/Section_Polling/Section_Polling.ino
Original file line number Diff line number Diff line change
@@ -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);
}
Loading