-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
dt78_lcd_touch_jpg.ino
102 lines (91 loc) · 2.63 KB
/
dt78_lcd_touch_jpg.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*******************************************************************************
* Dependent libraries:
* - JPEGDEC
* - CST816S
* - Arduino_GFX_Library
*
* Download using library manager
*
* Setup steps:
* 1. Change your LCD parameters in Arduino_GFX setting
* 2. Upload JPEG file
* SPIFFS (ESP32):
* upload SPIFFS data with ESP32 Sketch Data Upload:
* ESP32: https://github.com/lorol/arduino-esp32fs-plugin
*
*
* LCD <=> ESP32
* IOVCC - 3.3V
* VCC28 - 3.3V
* GND - GND
* SDA - 23
* SCLK - 18
* RST - 4
* CS - 15
* A0 - 2 //DC pin
* TE - Not Connected
* LEDA - 3.3V //backlight +
* LEDK - GND //backlight - (use an N-channel mosfet to control the backlight with any pin)
*
* TOUCH <=> ESP32
* VCC - 3.3V
* GND - GND
* TSCL - 22
* TSDA - 21
* TRST - 5
* TINT - 19
*
******************************************************************************/
#include <Arduino_GFX_Library.h>
#include <CST816S.h>
#include <SPIFFS.h>
#include "JpegClass.h"
CST816S touch(21, 22, 5, 19); // sda, scl, rst, irq
Arduino_DataBus *bus = new Arduino_HWSPI(2 /* DC */, 15 /* CS */);
Arduino_GFX *gfx = new Arduino_GC9A01(bus, 4, 0 /* rotation */, true /* IPS */);
static JpegClass jpegClass;
// pixel drawing callback
static int jpegDrawCallback(JPEGDRAW *pDraw) {
gfx->draw16bitBeRGBBitmap(pDraw->x, pDraw->y, pDraw->pPixels, pDraw->iWidth, pDraw->iHeight);
return 1;
}
int x = 0;
int y = 15;
char * images[] = {"/0.jpg", "/1.jpg", "/2.jpg", "/3.jpg", "/4.jpg", "/5.jpg", "/6.jpg", "/7.jpg",
"/8.jpg", "/9.jpg", "/10.jpg", "/11.jpg", "/12.jpg", "/13.jpg", "/14.jpg", "/15.jpg"
};
void setup() {
Serial.begin(115200);
// while (!Serial);
Serial.println("JPEG Image Viewer");
// Init Display
gfx->begin();
gfx->fillScreen(BLACK);
touch.begin();
if (!SPIFFS.begin()) {
Serial.println(F("ERROR: File System Mount Failed!"));
gfx->println(F("ERROR: File System Mount Failed!"));
return;
} else {
jpegClass.draw( &SPIFFS, (char *)images[x], jpegDrawCallback, true , 0 , 0 , gfx->width(), gfx->height());
}
}
void loop() {
if (touch.available()) {
if (touch.data.gestureID == SWIPE_LEFT) {
x++;
if (x > y) {
x = 0;
}
jpegClass.draw( &SPIFFS, (char *)images[x], jpegDrawCallback, true , 0 , 0 , gfx->width(), gfx->height());
}
if (touch.data.gestureID == SWIPE_RIGHT) {
x--;
if (x < 0) {
x = y;
}
jpegClass.draw(&SPIFFS, (char *)images[x], jpegDrawCallback, true , 0 , 0 , gfx->width(), gfx->height());
}
delay(100);
}
}