Closed modi12jin closed 3 years ago
Add library
https://github.com/DustinWatts/FT6236
main.cpp
#include <Arduino.h>
#include <WiFi.h>
#include <SPI.h>
#include <Arduino_GFX_Library.h>
#include <FT6236.h>
#include <VNC_ST7796.h>
#include <VNC.h>
const char * vnc_ip = "192.168.0.107";
const uint16_t vnc_port = 5900;
const char * vnc_pass = "12345678";
const char* ssid = "FAST_BA74";
const char* password = "XXXXXXXXX";
#define TFT_BL 23
Arduino_ESP32SPI *bus = new Arduino_ESP32SPI(21 /* DC */, 15 /* CS */, 14 /* SCK */, 13 /* MOSI */,-1);
ST7796VNC tft = ST7796VNC(bus);
arduinoVNC vnc = arduinoVNC(&tft);
FT6236 ts = FT6236();
void TFTnoWifi(void) {
tft.fillScreen(BLACK);
tft.setCursor(0, ((tft.getHeight() / 2) - (5 * 8)));
tft.setTextColor(RED);
tft.setTextSize(5);
tft.println("NO WIFI!");
tft.setTextSize(2);
tft.println();
}
void TFTnoVNC(void) {
tft.fillScreen(BLACK);
tft.setCursor(0, ((tft.getHeight() / 2) - (4 * 8)));
tft.setTextColor(GREEN);
tft.setTextSize(4);
tft.println("connect VNC");
tft.setTextSize(2);
tft.println();
tft.print(vnc_ip);
tft.print(":");
tft.println(vnc_port);
}
void setup(void) {
//Serial.begin(115200);
//Serial.setDebugOutput(true);
Serial.println();
Serial.println();
//LCD屏幕初始化
tft.begin(); /* TFT init */
tft.setRotation(1);//为横屏方向
tft.height();
//显示屏背光
ledcSetup(10, 5000/*freq*/, 10 /*resolution*/);
ledcAttachPin(TFT_BL, 10);
analogReadResolution(10);
ledcWrite(10,300);
//begin(40, SDA, SCL) for custom pins
if (!ts.begin(40,18,19)){
Serial.println("Unable to start the capacitive touchscreen.");
}
tft.fillScreen(BLUE);
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
TFTnoWifi();
while(WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
TFTnoVNC();
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.println(F("[SETUP] VNC..."));
vnc.begin(vnc_ip, vnc_port);
vnc.setPassword(vnc_pass); // optional
}
void loop() {
if(WiFi.status() != WL_CONNECTED) {
vnc.reconnect();
TFTnoWifi();
delay(100);
} else {
if(vnc.connected()) {
int16_t touchX, touchY;
TS_Point p = ts.getPoint();
touchX=480-p.y;
touchY=p.x;
static unsigned long lastUpdateP;
static unsigned long lastUpdateR;
static uint16_t lx, ly;
if(ts.touched())
{
if((millis() - lastUpdateP) > 20) {
vnc.mouseEvent(touchX, touchY, 0b001);
lx = touchX;
ly = touchY;
lastUpdateP = millis();
//Serial.printf("[Touch] press: 1 X: %d Y: %d\n", touchX, touchY);
}
lastUpdateR = 0;
}else{
if((millis() - lastUpdateR) > 20) {
vnc.mouseEvent(lx, ly, 0b000);
lastUpdateR = millis();
//Serial.printf("[Touch] press: 0 X: %d Y: %d\n", lx, ly);
}
lastUpdateP = 0;
}
}
vnc.loop();
if(!vnc.connected()) {
TFTnoVNC();
delay(5000);
}
}
}