Skip to content

Commit fb0c3ac

Browse files
authored
Merge pull request #4 from arduino-libraries/karlsoderby/add-gfx-examples
Add GFX Examples + GFX dependency
2 parents ffc64f8 + f811c46 commit fb0c3ac

File tree

5 files changed

+146
-1
lines changed

5 files changed

+146
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
This example uses the Arduino_GigaDisplay_GFX library
3+
to draw some geometrical shapes on a 800x480 canvas.
4+
5+
The circuit:
6+
- GIGA R1 WiFi
7+
- GIGA Display Shield
8+
9+
created 10 sept 2023
10+
by Karl Söderby
11+
12+
This example code is in the public domain.
13+
*/
14+
15+
#include "Arduino_GigaDisplay_GFX.h"
16+
17+
GigaDisplay_GFX display;
18+
19+
#define WHITE 0xffff
20+
#define BLACK 0x0000
21+
22+
void setup() {
23+
display.begin();
24+
display.fillScreen(WHITE);
25+
display.drawTriangle(100, 200, 300, 400, 300, 600, BLACK);
26+
display.drawCircle(100, 100, 50, BLACK);
27+
display.drawRect(10, 650, 300, 80, BLACK);
28+
display.drawRoundRect(300, 50, 100, 100, 30, BLACK);
29+
}
30+
void loop() {}
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
This example uses the Arduino_GigaDisplay_GFX library
3+
to print "Hello World!" on a 800x480 canvas.
4+
5+
The circuit:
6+
- GIGA R1 WiFi
7+
- GIGA Display Shield
8+
9+
created 10 sept 2023
10+
by Karl Söderby
11+
12+
This example code is in the public domain.
13+
*/
14+
15+
#include "Arduino_GigaDisplay_GFX.h"
16+
17+
GigaDisplay_GFX display; // create the object
18+
19+
#define BLACK 0x0000
20+
21+
void setup() {
22+
display.begin();
23+
display.fillScreen(BLACK);
24+
display.setCursor(10,10); //x,y
25+
display.setTextSize(5); //adjust text size
26+
display.print("Hello World!"); //print
27+
}
28+
void loop(){}
+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
This example uses the Arduino_GigaDisplayTouch and
3+
Arduino_GigaDisplay_GFX library to change the
4+
display whenever it is touched, inverting the colors.
5+
6+
The circuit:
7+
- GIGA R1 WiFi
8+
- GIGA Display Shield
9+
10+
created 10 sept 2023
11+
by Karl Söderby
12+
13+
This example code is in the public domain.
14+
*/
15+
16+
#include "Arduino_GigaDisplay_GFX.h"
17+
#include "Arduino_GigaDisplayTouch.h"
18+
19+
Arduino_GigaDisplayTouch touchDetector;
20+
GigaDisplay_GFX display;
21+
22+
#define WHITE 0xffff
23+
#define BLACK 0x0000
24+
25+
#define screen_size_x 480
26+
#define screen_size_y 800
27+
28+
int touch_x;
29+
int touch_y;
30+
31+
int lastTouch;
32+
int threshold = 250;
33+
34+
bool switch_1;
35+
36+
void setup() {
37+
// put your setup code here, to run once:
38+
Serial.begin(9600);
39+
display.begin();
40+
41+
if (touchDetector.begin()) {
42+
Serial.print("Touch controller init - OK");
43+
} else {
44+
Serial.print("Touch controller init - FAILED");
45+
while (1)
46+
;
47+
}
48+
changeSwitch();
49+
}
50+
51+
void loop() {
52+
uint8_t contacts;
53+
GDTpoint_t points[5];
54+
contacts = touchDetector.getTouchPoints(points);
55+
56+
if (contacts > 0 && (millis() - lastTouch > threshold)) {
57+
Serial.print("Contacts: ");
58+
Serial.println(contacts);
59+
60+
//record the x,y coordinates
61+
for (uint8_t i = 0; i < contacts; i++) {
62+
touch_x = points[i].x;
63+
touch_y = points[i].y;
64+
}
65+
66+
//as the display is 480x800, anywhere you touch the screen it will trigger
67+
if (touch_x < screen_size_x && touch_y < screen_size_y) {
68+
switch_1 = !switch_1;
69+
Serial.println("switched");
70+
changeSwitch();
71+
}
72+
lastTouch = millis();
73+
}
74+
}
75+
76+
void changeSwitch() {
77+
if (switch_1) {
78+
display.fillScreen(BLACK);
79+
display.setTextColor(WHITE);
80+
} else {
81+
display.fillScreen(WHITE);
82+
display.setTextColor(BLACK);
83+
}
84+
display.setCursor(50, screen_size_y/2);
85+
display.setTextSize(5);
86+
display.print("Switched");
87+
}

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ category=Device Control
88
url=https://www.arduino.cc/
99
architectures=mbed_giga
1010
includes=Arduino_GigaDisplay.h
11-
depends=Arduino_BMI270_BMM150,Arduino_GigaDisplayTouch,ArduinoGraphics,lvgl
11+
depends=Arduino_BMI270_BMM150,Arduino_GigaDisplayTouch,ArduinoGraphics,Arduino_GigaDisplay_GFX,lvgl

0 commit comments

Comments
 (0)