Closed yeodeanyeo closed 2 years ago
C:\Users\Yeo Dean\Documents\Arduino\ESP32_ILI9341_MY_Menu\ESP32_ILI9341_MY_Menu.ino: In function 'void setup()':
C:\Users\Yeo Dean\Documents\Arduino\ESP32_ILI9341_MY_Menu\ESP32_ILI9341_MY_Menu.ino:361:54: warning: ISO C++ forbids converting a string constant to 'char' [-Wwrite-strings]
getstarted.initButton(17.5,240,205,30,"Get Started"); //First Button to bring up 2nd Screen
^
C:\Users\Yeo Dean\Documents\Arduino\ESP32_ILI9341_MY_Menu\ESP32_ILI9341_MY_Menu.ino: At global scope:
ESP32_ILI9341_MY_Menu:367:3: error: 'buttonjump' does not name a type
buttonjump.initButton(17.5,120,100,30,"JUMP");
^~~~~~
C:\Users\Yeo Dean\Documents\Arduino\ESP32_ILI9341_MY_Menu\ESP32_ILI9341_MY_Menu.ino: In function 'void loop()':
C:\Users\Yeo Dean\Documents\Arduino\ESP32_ILI9341_MY_Menu\ESP32_ILI9341_MY_Menu.ino:426:45: warning: ISO C++ forbids converting a string constant to 'char' [-Wwrite-strings]
buttonwifi.initButton(80,dist,80,30,"WIFI");
^
C:\Users\Yeo Dean\Documents\Arduino\ESP32_ILI9341_MY_Menu\ESP32_ILI9341_MY_Menu.ino:460:51: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
buttontemp.initButton(17.5,240,205,30,"GET TEMP"); //"TEMP" fits just nice in the colored box
^
Using library SPI at version 2.0.0 in folder: C:\Users\Yeo Dean\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.2\libraries\SPI
Using library Adafruit_GFX_Library at version 1.11.1 in folder: C:\Users\Yeo Dean\Documents\Arduino\libraries\Adafruit_GFX_Library
Using library Adafruit_ILI9341 at version 1.5.11 in folder: C:\Users\Yeo Dean\Documents\Arduino\libraries\Adafruit_ILI9341
Using library ThingPulse_XPT2046_Touch at version 1.4 in folder: C:\Users\Yeo Dean\Documents\Arduino\libraries\ThingPulse_XPT2046_Touch
Using library TouchEvent at version 1.3 in folder: C:\Users\Yeo Dean\Documents\Arduino\libraries\TouchEvent
Using library Adafruit_MLX90614_Library at version 2.1.3 in folder: C:\Users\Yeo Dean\Documents\Arduino\libraries\Adafruit_MLX90614_Library
Using library Adafruit_BusIO at version 1.11.3 in folder: C:\Users\Yeo Dean\Documents\Arduino\libraries\Adafruit_BusIO
Using library Wire at version 2.0.0 in folder: C:\Users\Yeo Dean\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.2\libraries\Wire
Using library WiFiManager at version 2.0.11-beta in folder: C:\Users\Yeo Dean\Documents\Arduino\libraries\WiFiManager
Using library WiFi at version 2.0.0 in folder: C:\Users\Yeo Dean\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.2\libraries\WiFi
Using library Update at version 2.0.0 in folder: C:\Users\Yeo Dean\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.2\libraries\Update
Using library WebServer at version 2.0.0 in folder: C:\Users\Yeo Dean\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.2\libraries\WebServer
Using library DNSServer at version 2.0.0 in folder: C:\Users\Yeo Dean\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.2\libraries\DNSServer
Using library FS at version 2.0.0 in folder: C:\Users\Yeo Dean\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.2\libraries\FS
exit status 1
'buttonjump' does not name a type
This repository is for TFT_eSPI only. Your sketch uses the Adafruit library, which I do not provide support.
In this example i follow a tutorial for the ILI9341 or XPT2046 LCD Screen on ESP32 DEVKit.
I dont know how to 'class' function works. All i know is it is used to create the buttons on screen? I was working with 3 buttons on screen using this code. when i created the 4th button using the 'class Buttonjump...' It gave me errors for all 4 buttons.
include "SPI.h"
include //Screen
include
include
include "Math.h"
//#include //Battery Fuel Gauge
//#include
//#include
include <Fonts/FreeSans9pt7b.h> //used font5
include "TouchEvent.h" //Touch Event
include //Temperature Sensor
include
include
include //WIFI
include "Wifi.h"
//#include //Upload data online
include
include
//-----------------------------------------------------PINOUTS in order for ILI9341
define TS_IRQ 5 //touch screen interrupt
define TS_OUT 19
define TS_DIN 23
define TS_CS 26 //touch screen chip select
define TS_CLK 18
define TFT_MISO 12
define TFT_LED 25 //WHITE WIRE
define TFT_CLK 14
define TFT_MOSI 13
define TFT_DC 2 //
define TFT_RST 4 // UART 2 RX - PIN 16 it was 4
define TFT_CS 15
define ROTATION 0
//-----------------------------------------------------Initialises Libraries Adafruit_MLX90614 mlx = Adafruit_MLX90614(); Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO); //XPT2046_Touchscreen ts(TS_CS, TS_IRQ); XPT2046_Touchscreen ts (TS_CS); TouchEvent tevent(ts); //ts is declared for XPT_Touchscreen
//-----------------------------------------------------Color Definition // Color definitions
define BLACK 0x0000 ///< 0, 0, 0
define NAVY 0x000F ///< 0, 0, 123
define DARKGREEN 0x03E0 ///< 0, 125, 0
define DARKCYAN 0x03EF ///< 0, 125, 123
define MAROON 0x7800 ///< 123, 0, 0
define PURPLE 0x780F ///< 123, 0, 123
define OLIVE 0x7BE0 ///< 123, 125, 0
define LIGHTGREY 0xC618 ///< 198, 195, 198
define DARKGREY 0x7BEF ///< 123, 125, 123
define BLUE 0x001F ///< 0, 0, 255
define GREEN 0x07E0 ///< 0, 255, 0
define CYAN 0x07FF ///< 0, 255, 255
define RED 0xF800 ///< 255, 0, 0
define MAGENTA 0xF81F ///< 255, 0, 255
define YELLOW 0xFFE0 ///< 255, 255, 0
define WHITE 0xFFFF ///< 255, 255, 255
define ORANGE 0xFD20 ///< 255, 165, 0
define GREENYELLOW 0xAFE5 ///< 173, 255, 41
define PINK 0xFC18 ///< 255, 130, 198
//-----------------------------------------------------Prototypes (avoid compliation error) void temperaturedata(); void removeone(); void wificonnect(); void UpdateLocalTime(String Format);
//-----------------------------------------------------Global Variables //int scr = 0; //uint16_t bg[4] = {BLACK,RED,GREEN,YELLOW}; //TEST TS_Point last; boolean draw; int myCounter = 0; //variable int t = 0; unsigned long lastFrame = millis();
float wificount = 0;
//------------------Upload variables----------------------------- unsigned long myChannel = 1776473; //Upload String myAPI = "PWDZZEJNVBF0UG9X"; //Upload const char* server ="api.thingspeak.com"; //Upload
String Date_str, Time_str, Time_format,Day_str; //Time and Date WiFiManager wm; //wifi float wificonnected = 0; //wifi
//--------------------------------------------------------------Variables //float amb = mlx.readAmbientTempC(); //read ambient temperature //float obj = mlx.readObjectTempC(); //read object temperature
//float percent = FuelGauge.percent(); //float voltage = FuelGauge.voltage();
//DFRobot_MAX17043 gauge; //FuelGauge Max; //not working
// code removed cause its a global variable and im only using in LOOP boolean buttonenable1 = true; //GetStarted boolean buttonenable2 = false; //Wifi boolean buttonenable3 = false; //temperature
//-----------------------------------------------------
//------------------------------Calibration Values------------------------------------------
float xCalM = -0.07, yCalM = -0.09; // gradients float xCalC = 259.22, yCalC = 354.07; // y axis crossing points
//int8_t blockWidth = 20; // block size //int8_t blockHeight = 20; //int16_t blockX = 0, blockY = 0; // block position (pixels)
class ScreenPoint { public: int16_t x = 3489; int16_t y = 3639; float x2 = 572; float y2 = 589;
ScreenPoint(){ // default contructor }
ScreenPoint(int16_t xIn, int16_t yIn){ x = xIn; y = yIn; } };
//-------------------------Class Buttontemp
class Buttontemp { public:
int x; int y; int width; int height; char *text;
Buttontemp(){}
//void initButton(int xPos, int yPos, int butWidth, int butHeight, char butText){ void initButton(int xPos, int yPos, int butWidth, int butHeight, char butText){ x = xPos; y = yPos; width = butWidth; height = butHeight; text = butText; render(); }
void render(){ tft.fillRect(x,y,width,height,GREEN);// draw rectangle tft.drawRect(x,y,width,height,WHITE); //(NEW) added border for button tft.setCursor(x+5,y+5); tft.setTextSize(3); tft.setTextColor(WHITE); tft.print(text); }
bool isClicked(ScreenPoint sp){ if ((sp.x >= x) && (sp.x <= (x+width)) && (sp.y >= y) && (sp.y <= (y+height))){ return true; } else { return false; } } };
Buttontemp buttontemp;
//-------------------------Class GetStarted class GetStarted { public:
int x; int y; int width; int height; char *text;
GetStarted(){}
//void initButton(int xPos, int yPos, int butWidth, int butHeight, char butText){ void initButton(int xPos, int yPos, int butWidth, int butHeight, char butText){ x = xPos; y = yPos; width = butWidth; height = butHeight; text = butText; render(); }
void render(){ tft.fillRect(x,y,width,height,RED);// draw rectangle tft.drawRect(x,y,width,height,WHITE); //(NEW) added border for button tft.setCursor(x+5,y+5); tft.setTextSize(3); tft.setTextColor(BLACK); tft.print(text); }
bool isClicked(ScreenPoint sp){ if ((sp.x >= x) && (sp.x <= (x+width)) && (sp.y >= y) && (sp.y <= (y+height))){ return true; } else { return false; } } };
GetStarted getstarted; //--------------------------WIFI class Buttonwifi{ public:
int x; int y; int width; int height; char *text;
Buttonwifi(){}
//void initButton(int xPos, int yPos, int butWidth, int butHeight, char butText){ void initButton(int xPos, int yPos, int butWidth, int butHeight, char butText){ x = xPos; y = yPos; width = butWidth; height = butHeight; text = butText; render(); }
void render(){ tft.fillRect(x,y,width,height,GREEN);// draw rectangle tft.drawRect(x,y,width,height,WHITE); //(NEW) added border for button tft.setCursor(x+5,y+5); tft.setTextSize(3); tft.setTextColor(BLACK); tft.print(text); }
bool isClicked(ScreenPoint sp){ if ((sp.x >= x) && (sp.x <= (x+width)) && (sp.y >= y) && (sp.y <= (y+height))){ return true; } else { return false; } } };
Buttonwifi buttonwifi; //------------------------------------------------------------JUMP JUMP JUMP JUMP JUMP class Buttonjump{ public:
int x; int y; int width; int height; char *text;
Buttonjump(){}
//void initButton(int xPos, int yPos, int butWidth, int butHeight, char butText){ void initButton(int xPos, int yPos, int butWidth, int butHeight, char butText){ x = xPos; y = yPos; width = butWidth; height = butHeight; text = butText; render(); }
void render(){ tft.fillRect(x,y,width,height,YELLOW);// draw rectangle tft.drawRect(x,y,width,height,WHITE); //(NEW) added border for button tft.setCursor(x+5,y+5); tft.setTextSize(2); tft.setTextColor(RED); tft.print(text); }
bool isClicked(ScreenPoint sp){ if ((sp.x >= x) && (sp.x <= (x+width)) && (sp.y >= y) && (sp.y <= (y+height))){ return true; } else { return false; } } };
Buttonjump buttonjump;
//------------------------------------------------------------ ScreenPoint getScreenCoords(int16_t x, int16_t y){ int16_t xCoord = round((x xCalM) + xCalC); int16_t yCoord = round((y yCalM) + yCalC); if(xCoord < 0) xCoord = 0; if(xCoord >= tft.width()) xCoord = tft.width() - 1; if(yCoord < 0) yCoord = 0; if(yCoord >= tft.height()) yCoord = tft.height() - 1; return(ScreenPoint(xCoord, yCoord)); } //---------------------------------------------------------------SETUP//////////////// void setup() { Serial.begin(115200); //FuelGauge.begin(); //-----initialise the battery gauge
pinMode(TS_CS, OUTPUT); //-----initialise touchpin digitalWrite(TS_CS, HIGH); pinMode(TFT_LED, OUTPUT); //-----powers screen with LED PIN digitalWrite(TFT_LED, HIGH); // pinMode(27,OUTPUT); //pinMode(2,OUTPUT);
//pinMode(,OUTPUT); //passive buzzer cant use 5, its IRQ
if (!mlx.begin()) { //initialise temperature sensor Serial.println("Error connecting to MLX sensor. Check wiring."); while (1); };
Serial.print("Emissivity = "); Serial.println(mlx.readEmissivity()); Serial.println("================================================");
tft.begin(); //-----initialise screen tft.setRotation(ROTATION); //-----set rotation tft.fillScreen(BLACK); ts.begin(); ts.setRotation(ROTATION);
//----------------Time code-------------- configTime(0,0, "sg.pool.ntp.org", "time.nist.gov"); setenv("TZ","<+08>-8",1); //singapore timezone Time_format = "M"; // or StartTime("I"); for Imperial 12:00 PM format and Date format MM-DD-CCYY e.g. 12:30PM 31-Mar-2019 UpdateLocalTime(Time_format);
//----------------1st Screen------------- tft.setCursor(32, 56); tft.setTextColor(WHITE,BLACK); tft.setTextSize(4); tft.print("Welcome!"); tft.setCursor(50,90); tft.setTextColor(WHITE,BLACK); tft.setTextSize(1); tft.print("FYP Smart Thermometer"); getstarted.initButton(17.5,240,205,30,"Get Started"); //First Button to bring up 2nd Screen
//calibrateTouchScreen(); //removed calibration to avoid calibrating all the time. i added the code into the tabs }
buttonjump.initButton(17.5,120,100,30,"JUMP");
//--------------------------------------------------LOOP BEGIN void loop() {
int dist=275; //represents distance apart from sentence of word int distapart0=90; int distapart1=20; int distapart2=40; int j; //int sc; ScreenPoint sp; // float a = mlx.readAmbientTempC(); //ambient temperature // float o = mlx.readObjectTempC(); //object temperature
//---------------------------------------------------Check if Temperature Sensor works //if (isnan(a) || isnan(0)){
// Serial.println("Failed to read from Temperature Sensor!"); // return;}
//--------------------------------------------------- // while((millis() - lastFrame) < 20); //conditioning // lastFrame = millis();
//----------Instructions for WIFI (2nd Screen)--------- if(ts.touched()){ //when screen touched, reads the touch position TS_Point p = ts.getPoint(); sp = getScreenCoords(p.x, p.y); //stores the touched location if(getstarted.isClicked(sp) &&buttonenable1){ //if touched location is at button, code runs buttonenable1 = false; tft.fillScreen(BLACK); //tft.drawRect(0,56,160,90, BLACK); tft.setCursor(32,20); // "Instructions" tft.setTextColor(WHITE); tft.setTextSize(2); tft.println("Instructions"); tft.setCursor(5,distapart0); //instruction 1 tft.setTextColor(WHITE); tft.setTextSize(1); tft.println("1:Use your phone to make a connection"); tft.setCursor(5,distapart0+13); tft.println("to the SmartThermometerFYP wifi"); tft.println(""); tft.setCursor(5,distapart0+36);// instruction 2 tft.setTextSize(1); tft.println("2:Click on configure WiFi"); tft.println(""); tft.setCursor(5,146); tft.println("3:Select and Connect to a WIFI that you"); tft.setCursor(5,159); tft.print("have access"); tft.setCursor(5,182); tft.println("4:Wait for the pop-up screen to close"); tft.println(""); //--------------------------------------IF Sucess or unsucess with wifi connection tft.setCursor(5,dist-distapart2); tft.println("SUCCESS:proceed automatically."); tft.setCursor(5,dist-distapart1); tft.println("UNSUCCESSFUL:repeat steps 1 to 4 again."); buttonenable2 = true; buttonwifi.initButton(80,dist,80,30,"WIFI");
}
}
//---------------------------------------------------------------------Wifi Codes if(ts.touched()){ //when screen touched, reads the touch position TS_Point p = ts.getPoint(); sp = getScreenCoords(p.x, p.y); if(buttonwifi.isClicked(sp) &&buttonenable2){ buttonenable2 = false; wificonnect(); } }
//--------Show TEMP SCREEN (Last Screen/ Main Screen)----- (take temperature data here)
if(wificonnected > 0){ //Will keep looping be //---------------------------------------------------------------Initialise Time UpdateLocalTime(Time_format); Serial.println(Date_str); Serial.println(Day_str); Serial.println(Time_str); Serial.println(); tft.setCursor(45,56); tft.setTextColor(WHITE,BLACK); tft.setTextSize(5); //size 4 perviously tft.print(Time_str);
//delay(60000); //60seconds / 1minute }
if(t==5){ buttonenable3 = true; buttontemp.initButton(17.5,240,205,30,"GET TEMP"); //"TEMP" fits just nice in the colored box t=t-5; }
//------------------------------------------------------------------TEMP if(ts.touched()){ //when screen touched, reads the touch position
if(buttontemp.isClicked(sp) && buttonenable3){ buttonenable3 = false ; tft.setCursor(80,100); tft.setTextColor(WHITE); digitalWrite(2,HIGH); tft.setTextSize(3); tft.setCursor(80,150); tft.setTextColor(WHITE); tft.print(mlx.readObjectTempC()); // tft.setTextSize(1.5); // tft.setCursor(150,100); // tft.setTextColor(WHITE,BLACK); // tft.print("TAKE TEMPERATURE"); temperaturedata(); buttonenable3 = true;
}
//---------------------------------------------------------------Initialise ThinkSpeak //ThingSpeak sends data only when temperature button pressed //Every 15-20s upload to ThinkSpeak
}
*/
// else { // tft.fillRect(0,100,125,30,BLACK); //clears data //} //} //else { //tft.fillRect(0,100,125,30,BLACK); //clears data //}
}//--------------------------------------------------------LOOP END