2024-12-0900 Jetzt geht TOUCH und SD.
This commit is contained in:
parent
8897226d9a
commit
7708e5cb38
|
@ -8,8 +8,8 @@ board = esp32dev
|
|||
framework = arduino
|
||||
lib_deps =
|
||||
bodmer/TFT_eSPI@^2.5.33
|
||||
;nitek/XPT2046_Bitbang_Slim@^2.0.0
|
||||
https://github.com/PaulStoffregen/XPT2046_Touchscreen.git#v1.4
|
||||
nitek/XPT2046_Bitbang_Slim @ 2.0.0
|
||||
;https://github.com/PaulStoffregen/XPT2046_Touchscreen.git#v1.4
|
||||
adafruit/Adafruit HTU21DF Library @ 1.0.5
|
||||
;wollewald/ADS1115_WE @ 1.4.3
|
||||
adafruit/Adafruit MCP9808 Library @ 2.0.0
|
||||
|
|
141
src/main.cpp
141
src/main.cpp
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include <Wire.h>
|
||||
|
||||
#include <XPT2046_Touchscreen.h>
|
||||
#include <XPT2046_Bitbang.h>
|
||||
|
||||
#include <WiFi.h>
|
||||
//#include <NTPClient.h>
|
||||
|
@ -31,11 +31,12 @@ char ausgabe[100];
|
|||
// 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
|
||||
#define MOSI_PIN 32
|
||||
#define MISO_PIN 39
|
||||
#define CLK_PIN 25
|
||||
#define CS_PIN 33
|
||||
|
||||
XPT2046_Bitbang touchscreen(MOSI_PIN, MISO_PIN, CLK_PIN, CS_PIN);
|
||||
|
||||
#define SD_SCK 18
|
||||
#define SD_MISO 19
|
||||
|
@ -46,7 +47,6 @@ TFT_eSPI tft = TFT_eSPI();
|
|||
SPIClass spi2 = SPIClass(VSPI);
|
||||
|
||||
SPIClass mySpi = SPIClass(VSPI);
|
||||
XPT2046_Touchscreen ts(XPT2046_CS, XPT2046_IRQ);
|
||||
|
||||
|
||||
#include<mess_htu21.h>
|
||||
|
@ -61,6 +61,8 @@ XPT2046_Touchscreen ts(XPT2046_CS, XPT2046_IRQ);
|
|||
bool getNTPtime(int sec);
|
||||
void showTime(tm localTime);
|
||||
void zeigeZeit(tm localTime, int x, int y);
|
||||
void drawMenue(int32_t xs, int32_t sy);
|
||||
void Menue();
|
||||
|
||||
void listDir(fs::FS &fs, const char * dirname, uint8_t levels) {
|
||||
Serial.printf("Listing directory: %s\n", dirname);
|
||||
|
@ -228,6 +230,8 @@ void setup() {
|
|||
//spi2.begin(XPT2046_CLK, XPT2046_MISO, XPT2046_MOSI, XPT2046_CS);
|
||||
/* ts.begin(spi2);
|
||||
ts.setRotation(1); */
|
||||
touchscreen.begin();
|
||||
//touchscreen.setCalibration(1,320,1,240);
|
||||
mySpi.begin(SD_SCK, SD_MISO, SD_MOSI);
|
||||
|
||||
// Start the tft display and set it to black
|
||||
|
@ -245,7 +249,7 @@ void setup() {
|
|||
x = 320 /2;
|
||||
y += 16;
|
||||
tft.setTextColor(TFT_RED, TFT_BLACK);
|
||||
tft.drawCentreString("Warte auf verbindung", x, y, fontNum *= 2);
|
||||
tft.drawCentreString("Warte auf Verbindung", x, y, fontNum *= 2);
|
||||
Serial.begin(115200);
|
||||
WiFi.reconnect();
|
||||
delay(10);
|
||||
|
@ -315,7 +319,6 @@ void setup() {
|
|||
tft.setTextSize(2);
|
||||
tft.println(WiFi.localIP());
|
||||
tft.setTextSize(1);
|
||||
delay(5000);
|
||||
// Initialize a NTPClient to get time
|
||||
configTime(0, 0, NTP_SERVER);
|
||||
// See https://github.com/nayarsystems/posix_tz_db/blob/master/zones.csv for Timezone codes for your region
|
||||
|
@ -351,7 +354,7 @@ void setup() {
|
|||
tft.setTextColor(TFT_BLUE, TFT_BLACK);
|
||||
}
|
||||
|
||||
void printTouchToDisplay(TS_Point p) {
|
||||
void printTouchToDisplay(TouchPoint p) {
|
||||
|
||||
// Clear screen first
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
|
@ -361,7 +364,7 @@ void printTouchToDisplay(TS_Point p) {
|
|||
int y = 100;
|
||||
int fontSize = 2;
|
||||
|
||||
String temp = "Pressure = " + String(p.z);
|
||||
String temp = "Pressure = " + String(p.zRaw);
|
||||
tft.drawCentreString(temp, x, y, fontSize);
|
||||
|
||||
y += 16;
|
||||
|
@ -374,9 +377,9 @@ void printTouchToDisplay(TS_Point p) {
|
|||
}
|
||||
|
||||
|
||||
void printTouchToSerial(TS_Point p) {
|
||||
void printTouchToSerial(TouchPoint p) {
|
||||
Serial.print("Pressure = ");
|
||||
Serial.print(p.z);
|
||||
Serial.print(p.zRaw);
|
||||
Serial.print(", x = ");
|
||||
Serial.print(p.x);
|
||||
Serial.print(", y = ");
|
||||
|
@ -401,18 +404,18 @@ int ts_x, ts_y, ts_z;
|
|||
|
||||
void loop() {
|
||||
|
||||
if (ts.tirqTouched() && ts.touched()) {
|
||||
TS_Point p = ts.getPoint();
|
||||
//printTouchToSerial(p);
|
||||
ts_x = map(p.x, 200, 3700, 1, SCREEN_WIDTH);
|
||||
ts_y = map(p.y, 240, 3800, 1, SCREEN_HEIGHT);
|
||||
ts_z = p.z;
|
||||
printTouchToSerial2(ts_x, ts_y, ts_z);
|
||||
TouchPoint touch = touchscreen.getTouch();
|
||||
if (touch.zRaw != 0){
|
||||
|
||||
if((ts_x >= 300) && (ts_y >= 220)){
|
||||
Serial.printf(" Gefunden bei: %i : %i : %i \t", p.y, p.x, p.z);
|
||||
} else {
|
||||
printTouchToDisplay(p);
|
||||
//printTouchToSerial(p);
|
||||
/* ts_x = map(touch.x, 200, 3700, 1, SCREEN_WIDTH);
|
||||
ts_y = map(touch.y, 240, 3800, 1, SCREEN_HEIGHT);
|
||||
ts_z = touch.zRaw ; */
|
||||
printTouchToSerial2(touch.x, touch.y, touch.xRaw);
|
||||
|
||||
if((touch.x >= 275) && (touch.y >= 210)){
|
||||
Serial.printf(" Gefunden bei: %i : %i : %i \t", touch.y, touch.x, touch.zRaw);
|
||||
Menue();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -427,6 +430,7 @@ void loop() {
|
|||
read_HTU21D();
|
||||
getTemperature_MCP9808();
|
||||
read_BMP_280();
|
||||
drawMenue(300,225);
|
||||
if (Minuten % SAVE_INTERVAL == 0){
|
||||
sprintf(ausgabe, "%s;%f;%f\n", szZeit, htuData.t, htuData.h);
|
||||
appendFile(SD, "/daten.csv", ausgabe);
|
||||
|
@ -475,4 +479,93 @@ void zeigeZeit(tm localTime, int x = 0, int y = 0){
|
|||
tft.println(szZeit);
|
||||
tft.setTextSize(1);
|
||||
}
|
||||
void drawMenue(int32_t xs, int32_t sy){
|
||||
tft.drawLine(xs,sy,xs+15,sy, TFT_YELLOW);
|
||||
tft.drawLine(xs,sy+5,xs+15,sy+5, TFT_YELLOW);
|
||||
tft.drawLine(xs,sy+10,xs+15,sy+10, TFT_YELLOW);
|
||||
}
|
||||
|
||||
void Menue(){
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
while(1){
|
||||
TouchPoint touch = touchscreen.getTouch();
|
||||
tft.setTextColor(TFT_YELLOW, TFT_BLACK);
|
||||
tft.drawCentreString("Einstellungen: ", 160, 20, 4);
|
||||
getNTPtime(10);
|
||||
tft.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||
zeigeZeit(timeinfo, 215, 0);
|
||||
tft.setCursor(1,50);
|
||||
tft.setTextSize(2);
|
||||
tft.println("Interval der Daten-\nsicherung (in Minuten).");
|
||||
if (touch.zRaw != 0){
|
||||
|
||||
printTouchToSerial2(touch.x, touch.y, touch.xRaw);
|
||||
|
||||
if(((touch.x >= 15) && (touch.x <= 55)) && ((touch.y >= 95) && (touch.y <= 125))){
|
||||
Serial.printf(" Gefunden bei 1: %i : %i : %i \t", touch.y, touch.x, touch.zRaw);
|
||||
tft.drawRoundRect(11,91,38,38,5,TFT_GOLD);
|
||||
tft.drawRoundRect(12,92,36,36,5,TFT_GOLD);
|
||||
tft.drawRoundRect(13,93,34,34,5,TFT_GOLD);
|
||||
delay(1000);
|
||||
tft.drawRoundRect(11,91,38,38,5,TFT_BLACK);
|
||||
tft.drawRoundRect(12,92,36,36,5,TFT_BLACK);
|
||||
tft.drawRoundRect(13,93,34,34,5,TFT_BLACK);
|
||||
}
|
||||
|
||||
if(((touch.x >= 65) && (touch.x <= 95)) && ((touch.y >= 95) && (touch.y <= 125))){
|
||||
Serial.printf(" Gefunden bei 2: %i : %i : %i \t", touch.y, touch.x, touch.zRaw);
|
||||
tft.drawRoundRect(61,91,38,38,5,TFT_GOLD);
|
||||
tft.drawRoundRect(62,92,36,36,5,TFT_GOLD);
|
||||
tft.drawRoundRect(63,93,34,34,5,TFT_GOLD);
|
||||
delay(1000);
|
||||
tft.drawRoundRect(61,91,38,38,5,TFT_BLACK);
|
||||
tft.drawRoundRect(62,92,36,36,5,TFT_BLACK);
|
||||
tft.drawRoundRect(63,93,34,34,5,TFT_BLACK);
|
||||
}
|
||||
if(((touch.x >= 110) && (touch.x <= 140)) && ((touch.y >= 95) && (touch.y <= 125))){
|
||||
Serial.printf(" Gefunden bei 3: %i : %i : %i \t", touch.y, touch.x, touch.zRaw);
|
||||
tft.drawRoundRect(111,91,38,38,5,TFT_GOLD);
|
||||
tft.drawRoundRect(112,92,36,36,5,TFT_GOLD);
|
||||
tft.drawRoundRect(113,93,34,34,5,TFT_GOLD);
|
||||
delay(1000);
|
||||
tft.drawRoundRect(111,91,38,38,5,TFT_BLACK);
|
||||
tft.drawRoundRect(112,92,36,36,5,TFT_BLACK);
|
||||
tft.drawRoundRect(113,93,34,34,5,TFT_BLACK);
|
||||
}
|
||||
if(((touch.x >= 150) && (touch.x <= 195)) && ((touch.y >= 95) && (touch.y <= 125))){
|
||||
Serial.printf(" Gefunden bei 4: %i : %i : %i \t", touch.y, touch.x, touch.zRaw);
|
||||
tft.drawRoundRect(161,91,38,38,5,TFT_GOLD);
|
||||
tft.drawRoundRect(162,92,36,36,5,TFT_GOLD);
|
||||
tft.drawRoundRect(163,93,34,34,5,TFT_GOLD);
|
||||
delay(1000);
|
||||
tft.drawRoundRect(161,91,38,38,5,TFT_BLACK);
|
||||
tft.drawRoundRect(162,92,36,36,5,TFT_BLACK);
|
||||
tft.drawRoundRect(163,93,34,34,5,TFT_BLACK);
|
||||
}
|
||||
if(((touch.x >= 200) && (touch.x <= 230)) && ((touch.y >= 95) && (touch.y <= 125))){
|
||||
Serial.printf(" Gefunden bei 5: %i : %i : %i \t", touch.y, touch.x, touch.zRaw);
|
||||
tft.drawRoundRect(211,91,38,38,5,TFT_GOLD);
|
||||
tft.drawRoundRect(212,92,36,36,5,TFT_GOLD);
|
||||
tft.drawRoundRect(213,93,34,34,5,TFT_GOLD);
|
||||
delay(1000);
|
||||
tft.drawRoundRect(211,91,38,38,5,TFT_BLACK);
|
||||
tft.drawRoundRect(212,92,36,36,5,TFT_BLACK);
|
||||
tft.drawRoundRect(213,93,34,34,5,TFT_BLACK);
|
||||
}
|
||||
}
|
||||
tft.drawRoundRect(10,90,40,40,5,TFT_GREEN);
|
||||
tft.drawRoundRect(60,90,40,40,5,TFT_GREEN);
|
||||
tft.drawRoundRect(110,90,40,40,5,TFT_GREEN);
|
||||
tft.drawRoundRect(160,90,40,40,5,TFT_GREEN);
|
||||
tft.drawRoundRect(210,90,40,40,5,TFT_GREEN);
|
||||
|
||||
tft.drawNumber(1, 25, 105);
|
||||
tft.drawNumber(5, 75, 105);
|
||||
tft.drawNumber(10, 120, 105);
|
||||
tft.drawNumber(30, 170, 105);
|
||||
tft.drawNumber(60, 220, 105);
|
||||
tft.setTextSize(1);
|
||||
delay(200);
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user