hello everyone
I'm using:
esp32 board
ILI9341 TFT screen
this is my code:
#include <SPI.h>
#include <TFT_eSPI.h>
#include <string.h>
#define len 256
#define default_xStart 5
#define default_yStart 80
#define default_width 80
#define default_height 50
TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
//const int default_height = 40;
const uint8_t font_size = 2;
const byte cornerRadius = 4;
const int default_btn_color = TFT_WHITE;
uint16_t x = 0, y = 0;
char color[len], message[len], clk_commands[len][4];
void printText(uint16_t Xstart, uint16_t Ystart, uint8_t size, char color[len], char message[len]);
uint16_t calData[5] = { 585, 3260, 329, 3289, 7 };
struct Square {
int xStart;
int yStart;
int width;
int height;
int color;
char touchMessage[len];
};
Square Lightbtn = {
default_xStart,
default_yStart,
default_width,
default_height,
default_btn_color,
"LIGHT",
};
Square Waterbtn = {
Lightbtn.xStart + Lightbtn.width + 35, //120
default_yStart,
default_width,
default_height,
default_btn_color,
"WATER"
};
Square Soundbtn = {
Waterbtn.xStart + Waterbtn.width + 30, //230
default_yStart,
default_width,
default_height,
default_btn_color,
"SOUND"
};
Square Okbtn = {
Soundbtn.xStart + 30,
200,
default_width - 20,
default_height - 10,
TFT_GREEN,
"Ok"
};
Square buttonArray[] = { Lightbtn, Waterbtn, Soundbtn, Okbtn };
void setup() {
Serial.begin(115200);
tft.setRotation(1);
tft.init();
//touch_calibrate();
tft.setTouch(calData);
tft.fillScreen(TFT_BLACK);
printText(5, 5, 2, TFT_WHITE, "How would you like to wake up?");
for (Square draw : buttonArray) {
drawSquare(draw);
if (draw.xStart == Okbtn.xStart && draw.yStart == Okbtn.yStart)
printText(draw.xStart + (draw.width / 3), draw.yStart + (draw.height / 4) + 5, font_size, TFT_WHITE, draw.touchMessage);
else
printText(draw.xStart + (draw.width / 4) - 7, draw.yStart + (draw.height / 4) + 7, font_size, TFT_BLUE, draw.touchMessage);
}
}
//--------------------------------------------------------------------------------------
void loop() {
checkTouched();
}
//------------------------------------------------------------------------------------------
// Code to run a screen calibration, not needed when calibration values set in setup()
void touch_calibrate() {
uint16_t calData[5];
uint8_t calDataOK = 0;
// Calibrate
tft.fillScreen(TFT_BLACK);
tft.setCursor(20, 0);
tft.setTextSize(font_size - 0.5);
tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.println("Touch corners as indicated");
tft.setTextFont(1);
tft.println();
tft.calibrateTouch(calData, TFT_MAGENTA, TFT_BLACK, 15);
Serial.println();
Serial.println();
Serial.println("// Use this calibration code in setup():");
Serial.print(" uint16_t calData[5] = ");
Serial.print("{ ");
for (uint8_t i = 0; i < 5; i++) {
Serial.print(calData[i]);
if (i < 4) Serial.print(", ");
}
Serial.println(" };");
Serial.print(" tft.setTouch(calData);");
Serial.println();
Serial.println();
tft.fillScreen(TFT_BLACK);
//tft.setTextColor(TFT_GREEN, TFT_BLACK);
Serial.println("Calibration complete!");
Serial.println("Calibration code sent to Serial port.");
}
//This function will take a Square struct and use these variables to display data
//It will save us more code the more elements we add
void drawSquare(Square toDraw) {
tft.fillRoundRect(
toDraw.xStart,
toDraw.yStart,
toDraw.width,
toDraw.height,
cornerRadius,
toDraw.color);
}
uint count_btn_touch = 0;
void checkTouched() {
if (tft.getTouch(&x, &y)) {
for (Square btn : buttonArray) {
if (x > btn.xStart && x < btn.xStart + btn.width && y > btn.yStart && y < btn.yStart + btn.height) {
if (count_btn_touch >= 3)
count_btn_touch = 0;
if (btn.yStart != Okbtn.yStart && btn.xStart != Okbtn.xStart) {
if (count_btn_touch == 0)
tft.fillRoundRect(Waterbtn.xStart - 5, Waterbtn.yStart + Waterbtn.height + 20, 210, 40, 20, TFT_BLACK);
delay(200);
printText(Lightbtn.xStart, Lightbtn.yStart + Lightbtn.height + 30, font_size, TFT_WHITE, "You chose");
printText(Waterbtn.xStart + (count_btn_touch * 70), Waterbtn.yStart + Waterbtn.height + 30, font_size, TFT_WHITE, btn.touchMessage);
if (count_btn_touch >= 1 && count_btn_touch <= 3)
printText(Waterbtn.xStart + (count_btn_touch * 70) - 10, Waterbtn.yStart + Waterbtn.height + 30, font_size, TFT_WHITE, ",");
//Serial.print(btn.touchMessage);
//Serial.print("\t");
count_btn_touch ++;
} else
for (int i = 0; i >= count_btn_touch; i++)
sprintf(clk_commands[i], "%s", btn.touchMessage);
}
}
Serial.print("x,y = ");
Serial.print(x);
Serial.print(",");
Serial.println(y);
}
}
void printText(uint16_t Xstart, uint16_t Ystart, uint8_t size, int color, char message[len]) {
tft.setCursor(Xstart, Ystart);
tft.setTextSize(size);
tft.setTextColor(color);
tft.print(message);
}
whenever I touch the bottom right corner of my TFT screen the esp keeps resetting the this message appears on the Seirla monitor
ets Jun 8 2016 00:22:57
rst:0x8 (TG1WDT_SYS_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1344
load:0x40078000,len:13864
load:0x40080400,len:3608
entry 0x400805f0
does anyone know what's the issue here?