TFT 3.2 inch mega relay control
hi
i'm trying program arduino control relay tft screen
so there 2 colors on tft screen half red(relay off) , other half green(relay on) want press green light turn relay , red light turn off relay.
i got controlling relay idk how how make go on when press green light cause @ moment when press green light, can turn relay on , when press again goes off. tried make colors 1 thing turn on when press green color or off when press red color can turn on , off both buttons on tft.
if guyz can me appreciate it.
thanks and im sorry english , i'm new arduino .
i got mega2560
3.2 inch ili9341 tft lcd
and tft lcd mega shield v2.2.
i'm trying program arduino control relay tft screen
so there 2 colors on tft screen half red(relay off) , other half green(relay on) want press green light turn relay , red light turn off relay.
i got controlling relay idk how how make go on when press green light cause @ moment when press green light, can turn relay on , when press again goes off. tried make colors 1 thing turn on when press green color or off when press red color can turn on , off both buttons on tft.
if guyz can me appreciate it.
thanks and im sorry english , i'm new arduino .
i got mega2560
3.2 inch ili9341 tft lcd
and 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 fonts using int relay = 8; // uncomment next line arduino 2009/uno utft myglcd(ili9327,38,39,40,41); // remember change model parameter suit 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); } } |
you not testing right conditions in area.
you need test region of screen touched off condition.
add
before
code: [select]
// off button
if (mytouch.dataavailable()){
mytouch.read();
x=mytouch.getx();
y=mytouch.gety();
digitalwrite(relay,1);
you need test region of screen touched off condition.
add
code: [select]
if ((x>=240) && (x<=390) && (y>=0)&& (y<=240));
before
code: [select]
digitalwrite(relay,1);
Arduino Forum > Using Arduino > Programming Questions > TFT 3.2 inch mega relay control
arduino
Comments
Post a Comment