Skip to content

Commit

Permalink
Merge pull request #91 from TheNitek/slideshow_touch
Browse files Browse the repository at this point in the history
Add touch support to slideshow examples
  • Loading branch information
witnessmenow authored Dec 16, 2023
2 parents f8b87f7 + b3091ec commit 4e379c1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
29 changes: 28 additions & 1 deletion Examples/Showcases/1-Slideshow/1-Slideshow.ino
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
// Can be installed from the library manager (Search for "TFT_eSPI")
// https://github.com/Bodmer/TFT_eSPI

#include <XPT2046_Bitbang.h>
// A library for interfacing with the touch screen
//
// Can be installed from the library manager (Search for "XPT2046_Bitbang_Slim")
// https://github.com/TheNitek/XPT2046_Bitbang_Arduino_Library

#include <SPI.h>

#include <SdFat.h>
Expand All @@ -31,9 +37,25 @@ typedef SdBaseFile File; // Avoid compile issues
// Can be installed from the library manager (Search for "JPEGDEC")
// https://github.com/bitbank2/JPEGDEC


// ----------------------------
// Touch Screen pins
// ----------------------------

// The CYD touch uses some non default
// SPI pins

#define XPT2046_IRQ 36
#define XPT2046_MOSI 32
#define XPT2046_MISO 39
#define XPT2046_CLK 25
#define XPT2046_CS 33

TFT_eSPI tft = TFT_eSPI();
JPEGDEC jpeg;

XPT2046_Bitbang ts = XPT2046_Bitbang(XPT2046_MOSI, XPT2046_MISO, XPT2046_CLK, XPT2046_CS);

// Functions to access a file on the SD card
SPIClass sdSpi = SPIClass(VSPI);
SdSpiConfig sdSpiConfig = SdSpiConfig(SS, DEDICATED_SPI, SD_SCK_MHZ(32), &sdSpi);
Expand Down Expand Up @@ -172,6 +194,8 @@ void setup() {
tft.writedata(1);
#endif

ts.begin();

// Initialize SD card
if(!sd.begin(sdSpiConfig)) {
// SD error, stop here
Expand Down Expand Up @@ -213,8 +237,11 @@ void setup() {
}

void loop() {
TouchPoint t = ts.getTouch();

// Display next image after 10 seconds or button press
if((millis() - timer > 10*1000) || buttonPressed) {
if((millis() - timer > 10*1000) || buttonPressed || t.zRaw > 0) {
Serial.printf("x: %d y: %d xRaw: %d yRaw: %d zRaw: %d\n", t.x, t.y, t.xRaw, t.yRaw, t.zRaw);
currentIndex++;
loadImage(currentIndex);
timer = millis();
Expand Down
2 changes: 2 additions & 0 deletions Examples/Showcases/1-Slideshow/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ lib_deps =
bodmer/TFT_eSPI@^2.5.33
bitbank2/JPEGDEC@^1.2.8
greiman/SdFat@^2.2.2
nitek/XPT2046_Bitbang_Slim@^2.0.0
monitor_speed = 115200
monitor_filters = esp32_exception_decoder
upload_speed = 921600
board_build.partitions=min_spiffs.csv
board_build.arduino.upstream_packages = no
build_flags =
-DUSER_SETUP_LOADED
-DILI9341_2_DRIVER
Expand Down

0 comments on commit 4e379c1

Please sign in to comment.