Skip to content

Commit

Permalink
Update example #24
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisxhe committed Mar 22, 2024
1 parent aa22152 commit f38e837
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
38 changes: 33 additions & 5 deletions examples/Arduino_GFX_HelloWorld/Arduino_GFX_HelloWorld.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
*/
#include <Arduino.h>
#include <Arduino_GFX_Library.h> // https://github.com/moononournation/Arduino_GFX.git

#include "TouchDrvCSTXXX.hpp"

#define GFX_DEV_DEVICE LILYGO_T_DISPLAY_S3_AMOLED

Arduino_DataBus *bus = new Arduino_ESP32QSPI(
6 /* cs */, 47 /* sck */, 18 /* d0 */, 7 /* d1 */, 48 /* d2 */, 5 /* d3 */);
Arduino_GFX *gfx = new Arduino_RM67162(bus, 17 /* RST */, 0 /* rotation */);
Arduino_GFX *gfx2;

TouchDrvCSTXXX touch;
bool _touchOnline = false;

void setBrightness(uint8_t value)
{
Expand All @@ -37,9 +38,25 @@ void setup()
pinMode(38, OUTPUT);
digitalWrite(38, OUTPUT);

touch.setPins(-1, 21);
bool res = touch.begin(Wire, CST816_SLAVE_ADDRESS, 3, 2);
if (!res) {
Serial.println("Failed to find CST816T - check your wiring!");
_touchOnline = false;
} else {
_touchOnline = true;
touch.setCenterButtonCoordinate(600, 120); //AMOLED 1.91 inch
Serial.println("CST816T init success!");
// Only 1.91 Inch AMOLED board support
touch.setHomeButtonCallback([](void *ptr) {
Serial.println("Home key pressed!");
}, NULL);
}

if (!gfx->begin()) {
Serial.println("gfx->begin() failed!");
}

gfx2 = new Arduino_Canvas(240, 536, gfx, 0, 0); // for Sprites
gfx2->begin(GFX_SKIP_OUTPUT_BEGIN); // Added the GFX_SKIP_OUTPUT_BEGIN so the Canvas class doesn’t try and initialise the display
gfx2->fillScreen(BLACK);
Expand All @@ -50,12 +67,23 @@ void setup()
gfx2->fillCircle(130, 130, 40, GREEN);
gfx2->flush();

//Test brightness
for (int i = 0; i < 255; i++) {
setBrightness(i);
delay(20);
}

}

void loop()
{
for (int i = 0; i < 255; i++) {
setBrightness(i);
delay(20);
if (_touchOnline) {
if (touch.isPressed()) {
int16_t x_array[1]; int16_t y_array[1];
if (touch.getPoint(x_array, y_array)) {
Serial.printf("X:%d Y:%d \n", x_array[0], y_array[0]);
}
}
}
delay(5);
}
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,5 @@ build_flags =
${env.build_flags}
lib_deps =
moononournation/GFX Library for Arduino @ ^1.3.7
lewisxhe/SensorLib @ 0.1.6

0 comments on commit f38e837

Please sign in to comment.