From f811c46cc44e8c3173a29ef4c50ac9fb8ab068c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20S=C3=B6derby?= <35461661+karlsoderby@users.noreply.github.com> Date: Wed, 27 Sep 2023 17:16:54 +0200 Subject: [PATCH] add gfx examples --- ...uinoLogoDrawing => ArduinoLogoDrawing.ino} | 0 .../geometrical-shapes/geometrical-shapes.ino | 30 +++++++ examples/gfx/hello-world/hello-world.ino | 28 ++++++ examples/gfx/touch-switch/touch-switch.ino | 87 +++++++++++++++++++ library.properties | 2 +- 5 files changed, 146 insertions(+), 1 deletion(-) rename examples/basic/ArduinoLogoDrawing/{ArduinoLogoDrawing => ArduinoLogoDrawing.ino} (100%) create mode 100644 examples/gfx/geometrical-shapes/geometrical-shapes.ino create mode 100644 examples/gfx/hello-world/hello-world.ino create mode 100644 examples/gfx/touch-switch/touch-switch.ino diff --git a/examples/basic/ArduinoLogoDrawing/ArduinoLogoDrawing b/examples/basic/ArduinoLogoDrawing/ArduinoLogoDrawing.ino similarity index 100% rename from examples/basic/ArduinoLogoDrawing/ArduinoLogoDrawing rename to examples/basic/ArduinoLogoDrawing/ArduinoLogoDrawing.ino diff --git a/examples/gfx/geometrical-shapes/geometrical-shapes.ino b/examples/gfx/geometrical-shapes/geometrical-shapes.ino new file mode 100644 index 0000000..873bbc6 --- /dev/null +++ b/examples/gfx/geometrical-shapes/geometrical-shapes.ino @@ -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() {} \ No newline at end of file diff --git a/examples/gfx/hello-world/hello-world.ino b/examples/gfx/hello-world/hello-world.ino new file mode 100644 index 0000000..ba99502 --- /dev/null +++ b/examples/gfx/hello-world/hello-world.ino @@ -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(){} \ No newline at end of file diff --git a/examples/gfx/touch-switch/touch-switch.ino b/examples/gfx/touch-switch/touch-switch.ino new file mode 100644 index 0000000..3c97b3d --- /dev/null +++ b/examples/gfx/touch-switch/touch-switch.ino @@ -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"); +} \ No newline at end of file diff --git a/library.properties b/library.properties index 6911c04..2cedd2b 100644 --- a/library.properties +++ b/library.properties @@ -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 \ No newline at end of file +depends=Arduino_BMI270_BMM150,Arduino_GigaDisplayTouch,ArduinoGraphics,Arduino_GigaDisplay_GFX,lvgl \ No newline at end of file