Skip to content

Commit

Permalink
add gfx examples
Browse files Browse the repository at this point in the history
  • Loading branch information
karlsoderby committed Sep 27, 2023
1 parent ffc64f8 commit f811c46
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 1 deletion.
30 changes: 30 additions & 0 deletions examples/gfx/geometrical-shapes/geometrical-shapes.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
This example uses the Arduino_GigaDisplay_GFX library
to draw some geometrical shapes on a 800x480 canvas.
The circuit:
- GIGA R1 WiFi
- GIGA Display Shield
created 10 sept 2023
by Karl Söderby
This example code is in the public domain.
*/

#include "Arduino_GigaDisplay_GFX.h"

GigaDisplay_GFX display;

#define WHITE 0xffff
#define BLACK 0x0000

void setup() {
display.begin();
display.fillScreen(WHITE);
display.drawTriangle(100, 200, 300, 400, 300, 600, BLACK);
display.drawCircle(100, 100, 50, BLACK);
display.drawRect(10, 650, 300, 80, BLACK);
display.drawRoundRect(300, 50, 100, 100, 30, BLACK);
}
void loop() {}
28 changes: 28 additions & 0 deletions examples/gfx/hello-world/hello-world.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
This example uses the Arduino_GigaDisplay_GFX library
to print "Hello World!" on a 800x480 canvas.
The circuit:
- GIGA R1 WiFi
- GIGA Display Shield
created 10 sept 2023
by Karl Söderby
This example code is in the public domain.
*/

#include "Arduino_GigaDisplay_GFX.h"

GigaDisplay_GFX display; // create the object

#define BLACK 0x0000

void setup() {
display.begin();
display.fillScreen(BLACK);
display.setCursor(10,10); //x,y
display.setTextSize(5); //adjust text size
display.print("Hello World!"); //print
}
void loop(){}
87 changes: 87 additions & 0 deletions examples/gfx/touch-switch/touch-switch.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
This example uses the Arduino_GigaDisplayTouch and
Arduino_GigaDisplay_GFX library to change the
display whenever it is touched, inverting the colors.
The circuit:
- GIGA R1 WiFi
- GIGA Display Shield
created 10 sept 2023
by Karl Söderby
This example code is in the public domain.
*/

#include "Arduino_GigaDisplay_GFX.h"
#include "Arduino_GigaDisplayTouch.h"

Arduino_GigaDisplayTouch touchDetector;
GigaDisplay_GFX display;

#define WHITE 0xffff
#define BLACK 0x0000

#define screen_size_x 480
#define screen_size_y 800

int touch_x;
int touch_y;

int lastTouch;
int threshold = 250;

bool switch_1;

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
display.begin();

if (touchDetector.begin()) {
Serial.print("Touch controller init - OK");
} else {
Serial.print("Touch controller init - FAILED");
while (1)
;
}
changeSwitch();
}

void loop() {
uint8_t contacts;
GDTpoint_t points[5];
contacts = touchDetector.getTouchPoints(points);

if (contacts > 0 && (millis() - lastTouch > threshold)) {
Serial.print("Contacts: ");
Serial.println(contacts);

//record the x,y coordinates
for (uint8_t i = 0; i < contacts; i++) {
touch_x = points[i].x;
touch_y = points[i].y;
}

//as the display is 480x800, anywhere you touch the screen it will trigger
if (touch_x < screen_size_x && touch_y < screen_size_y) {
switch_1 = !switch_1;
Serial.println("switched");
changeSwitch();
}
lastTouch = millis();
}
}

void changeSwitch() {
if (switch_1) {
display.fillScreen(BLACK);
display.setTextColor(WHITE);
} else {
display.fillScreen(WHITE);
display.setTextColor(BLACK);
}
display.setCursor(50, screen_size_y/2);
display.setTextSize(5);
display.print("Switched");
}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ category=Device Control
url=https://www.arduino.cc/
architectures=mbed_giga
includes=Arduino_GigaDisplay.h
depends=Arduino_BMI270_BMM150,Arduino_GigaDisplayTouch,ArduinoGraphics,lvgl
depends=Arduino_BMI270_BMM150,Arduino_GigaDisplayTouch,ArduinoGraphics,Arduino_GigaDisplay_GFX,lvgl

0 comments on commit f811c46

Please sign in to comment.