Be gentle lol
fairly new to this but love it. here's the idea, toggle a light on and off while changing the display. Sounds simple but im stumped. Here's what i got, can someone assist in making improvements? I've been at this for hours.
don't mind the mess.. a lot of stuff has been taken out to zero in on the issue
#include <Adafruit_GFX.h>
#include <Adafruit_TFTLCD.h>
#include <TouchScreen.h>
int LightRelay=25; //Change all these to relays LightRelay FanRelay HeatRelay
int FanRelay=27;
int HeatRelay=29;
int hotPin=48;
int x;
#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4
// Color definitions
#define BLACK 0x0000
#define NAVY 0x000F
#define DARKGREEN 0x03E0
#define DARKCYAN 0x03EF
#define MAROON 0x7800
#define PURPLE 0x780F
#define OLIVE 0x7BE0
#define LIGHTGREY 0xC618
#define DARKGREY 0x7BEF
#define BLUE 0x001F
#define GREEN 0x07E0
#define CYAN 0x07FF
#define RED 0xF800
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define ORANGE 0xFD20
#define GREENYELLOW 0xAFE5
#define PINK 0xF81F
#define YP A3
#define XM A2
#define YM 9
#define XP 8
#define TS_MINX 920
#define TS_MAXX 150
#define TS_MINY 120
#define TS_MAXY 940
#define STATUS_X 10
#define STATUS_Y 65
int relay = 53;
bool light;
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
void setup(void) {
Serial.begin(9600);
tft.reset();
uint16_t identifier = 0x9341;
tft.begin(identifier);
tft.setRotation(0);
tft.fillScreen(WHITE);
tft.fillRect(0,106.7,80,106.7,BLACK);
tft.drawRect(0,106.7,80,106.7,WHITE);
tft.drawRect(80,0,240,106.7,WHITE);
tft.fillRect(80,0,240,106.7,YELLOW);
tft.drawRect(80,106.7,240,106.7,WHITE);
tft.fillRect(80,106.7,240,106.7,CYAN);
tft.drawRect(80,213.4,240,106.7,WHITE);
tft.fillRect(80,213.4,240,106.7,RED);
tft.setTextSize(1);
tft.setCursor(0, 240);
tft.setTextColor(BLACK);
tft.println(" Humidity:");
tft.setTextSize(1);
tft.setCursor(0, 30);
tft.setTextColor(BLACK);
tft.println(" Temperature:");
}
#define MINPRESSURE 10
#define MAXPRESSURE 1000
void loop(void) {
digitalWrite(13, HIGH);
TSPoint p = ts.getPoint();
digitalWrite(13, LOW);
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
int lightn=0;
if (p.z > MINPRESSURE && p.z < MAXPRESSURE)
{
p.x = map(p.x, TS_MINX, TS_MAXX, tft.width(), 0);
p.y = tft.height() - (map(p.y, TS_MINY, TS_MAXY, tft.height(), 0));
if ((p.y > 0 && p.y < 106.7) && (p.x >80 && p.x < 240))
{
int x=lightn+1;
}
if(x>=3){
x=1;
}
if (x==1){
light=true;
}
if (x==2){
light=false;
}
if (light == true) {
tft.drawRect(80,0,240,106.7,WHITE);
tft.fillRect(80,0,240,106.7,YELLOW);
tft.setTextSize(2);
tft.setCursor(112, 50);
tft.setTextColor(BLACK);
tft.println("LIGHT ON!");
digitalWrite(LightRelay,HIGH);
Serial.println("Light on");
}
if (light == false) {
tft.drawRect(80,0,240,106.7,RED);
tft.fillRect(80,0,240,106.7,YELLOW);
tft.setTextSize(2);
tft.setCursor(132, 50);
tft.setTextColor(BLACK);
tft.println("LIGHT");
digitalWrite(LightRelay,LOW);
Serial.println("Light off");
}
delay(100);
}
}