Hi
I'm trying to program my arduino to control a relay with my tft screen
so there are 2 colors on my tft screen half red(relay off) and other half green(relay on) i want to press the green light to turn the relay and red light to turn off the relay.
I got to the controlling the relay but idk how to how to make it just to go on when i press the green light cause at the moment when i press the green light, i can turn the relay on and when i press it again it goes off. i tried to make the colors to do 1 thing only just to turn it ON when i press the green color or off when i press the red color but i can turn it on and off with both buttons on the tft.
If you guyz can help me i would really appreciate it.
thanks and im sorry for the English and I'm really new to arduino .
i got a Mega2560
3.2 Inch ILI9341 TFT LCD
and a tft lcd mega shield v2.2.
#include <TouchScreen.h>
//
#include <UTouch.h>
#include <UTFT.h>
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF820
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
// Declare which fonts we will be using
int Relay = 8;
// Uncomment the next line for Arduino 2009/Uno
UTFT myGLCD(ILI9327,38,39,40,41); // Remember to change the model parameter to suit your display module!
UTouch myTouch( 6, 5, 4, 3, 2);
int x, y;
void setup()
{
myGLCD.InitLCD();
myGLCD.clrScr();
myTouch.InitTouch();
myTouch.InitTouch(LANDSCAPE);
myTouch.setPrecision(PREC_MEDIUM);
OnOffButton();
Serial.begin(9600);
pinMode(Relay, OUTPUT);
}
void OnOffButton()
{
//on button
myGLCD.setColor(GREEN);
myGLCD.fillRect(0,0,240,240);
myGLCD.setColor(BLACK);
myGLCD.drawRoundRect(0,0,240,240);
//off button
myGLCD.setColor(RED);
myGLCD.fillRect(240,0,399,240);
myGLCD.setColor(BLACK);
myGLCD.drawRoundRect(240,0,399,240);
}
void loop()
{
if (myTouch.dataAvailable()){
myTouch.read();
x=myTouch.getX();
y=myTouch.getY();
if ((x>=0) && (x<=240) && (y>=0) && (y<=240));
digitalWrite(Relay,0);
}
// off button
if (myTouch.dataAvailable()){
myTouch.read();
x=myTouch.getX();
y=myTouch.getY();
digitalWrite(Relay,1);
}
}