Olá...estou implementando em meu aquario um lcd 5" com arduino mega, estou ligando um relay de 2 canais. No menu do lcd touch no botão 1 funciona o relay1 mas se coloco em outro botão o relay2 não funciona, mesmo copiando e colando trocando somente de relay1 para relay2.
#include <tinyFAT.h>
#include <UTFT.h>
#include <UTFT_tinyFAT.h>
#include <UTFT_Geometry.h>
#include <UTouch.h>
#include <UTFT_Buttons.h>
int color = 0;
word colorlist[] = {VGA_WHITE, VGA_BLACK, VGA_RED, VGA_BLUE, VGA_GREEN, VGA_FUCHSIA, VGA_YELLOW, VGA_AQUA};
int bsize = 4;
int RELAY1 = 9;
int RELAY2 = 8;
boolean RELAY1Check = false;
boolean RELAY2Check = false;
// Declare which fonts we will be using
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t Dingbats1_XL[];
extern uint8_t SevenSegNumFont[];
UTFT myGLCD(CTE50, 38, 39, 40, 41);
UTFT_tinyFAT myFiles(&myGLCD);
UTouch myTouch(6,5,4,3,2);
UTFT_Buttons myButtons(&myGLCD, &myTouch);
UTFT_Geometry geo(&myGLCD);
char* files800[]={"PIC801.RAW", "PIC802.RAW", "PIC803.RAW", "PIC804.RAW", "PIC805.RAW", "PIC806.RAW", "PIC807.RAW", "PIC808.RAW", "", ""}; // 800x480
char* files[12];
int picsize_x, picsize_y;
boolean display_rendertime=false; // Set this to true if you want the rendertime to be displayed after a picture is loaded
boolean display_filename=false; // Set this to false to disable showing of filename
word res;
long sm, em;
int but1, but2, but3, but4, but5, but6, butX, butY, pressed_button;
boolean default_colors = true;
void setup() {
myGLCD.InitLCD();
myGLCD.clrScr();
file.initFAT();
Serial.begin(9600);
pinMode(RELAY1, OUTPUT);
digitalWrite(RELAY1,LOW);
Serial.begin(9600);
pinMode(RELAY2, OUTPUT);
digitalWrite(RELAY2,LOW);
myGLCD.setColor(255,255,255);
myGLCD.setFont(SmallFont);
picsize_x=myGLCD.getDisplayXSize();
picsize_y=myGLCD.getDisplayYSize();
switch (picsize_x)
{
case 800:
for (int z=0; z<sizeof(files800)/sizeof(*files800);z++)
files[z] = files800[z];
break;
}
myTouch.InitTouch(LANDSCAPE);
myTouch.setPrecision(PREC_MEDIUM);
myButtons.setTextFont(BigFont);
myButtons.setSymbolFont(Dingbats1_XL);
but1 = myButtons.addButton( 77, 57, 280, 68, "Button 1");
but2 = myButtons.addButton( 443, 57, 280, 68, "Button 2");
but3 = myButtons.addButton( 77, 152, 280, 68, "Button 3");
but4 = myButtons.addButton( 443, 152, 280, 68, "Button 4");
but5 = myButtons.addButton( 77, 248, 280, 68, "Button 5");
but6 = myButtons.addButton( 443, 248, 280, 68, "Button 6");
butX = myButtons.addButton(628, 354, 97, 68, "a", BUTTON_SYMBOL);
butY = myButtons.addButton( 77, 354, 280, 68, "I", BUTTON_SYMBOL | BUTTON_SYMBOL_REP_3X);
myGLCD.setColor(VGA_WHITE);
myGLCD.drawRect(0, 0, 799, 479);
myGLCD.drawRect(10, 10, 789, 469);
myGLCD.setFont(BigFont);
myGLCD.print("You pressed:", 393, 365);
myGLCD.setColor(VGA_BLACK);
myGLCD.setBackColor(VGA_WHITE);
myGLCD.setFont(BigFont);
myGLCD.print("None ", 393, 400);
}
void loop() {
int pressed_button;
int current_demo;
myButtons.drawButtons();
current_demo = 0;
while(current_demo==0) {
if (myTouch.dataAvailable() == true) {
pressed_button = myButtons.checkButtons();
//current_demo = 0;
if (pressed_button==butY) {
if (default_colors) {
myButtons.setButtonColors(VGA_YELLOW, VGA_RED, VGA_YELLOW, VGA_BLUE, VGA_GRAY);
myButtons.relabelButton(butY, "_");
myButtons.drawButtons();
default_colors=false;
}
else
{
myButtons.setButtonColors(VGA_WHITE, VGA_GRAY, VGA_WHITE, VGA_RED, VGA_BLUE);
myButtons.relabelButton(butY, "I");
myButtons.drawButtons();
default_colors=true;
}
}
if (pressed_button==but1){
myGLCD.print("Button 1", 393, 400);
current_demo = 1;
}else if (pressed_button==but2){
myGLCD.print("Button 2", 393, 400);
current_demo = 2;
}else if (pressed_button==but3){
myGLCD.print("Button 3", 393, 400);
current_demo = 3;
}else if (pressed_button==but4){
myGLCD.print("Button 4", 393, 400);
current_demo = 4;
}else if (pressed_button==but5){
myGLCD.print("Button 5", 393, 400);
current_demo = 5;
}else if (pressed_button==but6){
myGLCD.print("Button 6", 393, 400);
current_demo = 6;
}else if (pressed_button==-1){
myGLCD.print("None ", 393, 400);
}
}
if(current_demo != 0)
{
if(current_demo==1){
Demo1();
//myGLCD.InitLCD(LANDSCAPE);
//myGLCD.clrScr();
Serial.begin(9600);
} else if(current_demo==2){
Demo2();
//myGLCD.InitLCD(LANDSCAPE);
//myGLCD.clrScr();
Serial.begin(9600);
}}}}
void Demo2(void)
{
//myGLCD.InitLCD(LANDSCAPE);
//myGLCD.clrScr();
myTouch.InitTouch(LANDSCAPE);
myTouch.setPrecision(PREC_MEDIUM);
Serial.begin(9600);
if(pressed_button==but2){ // then someone pressed button 1
if(RELAY2Check == false){ //Turn the relay ON
digitalWrite(RELAY2, HIGH);
RELAY2Check = true;
}
else if(RELAY2Check == true){ //Turn the relay OFF
digitalWrite(RELAY2, LOW);
RELAY2Check = false;
}
}
}
void Demo1(void)
{
//myGLCD.InitLCD(LANDSCAPE);
//myGLCD.clrScr();
myTouch.InitTouch(LANDSCAPE);
myTouch.setPrecision(PREC_MEDIUM);
Serial.begin(9600);
if(pressed_button==but1){ // then someone pressed button 1
if(RELAY1Check == false){ //Turn the relay ON
digitalWrite(RELAY1, HIGH);
RELAY1Check = true;
}
else if(RELAY1Check == true){ //Turn the relay OFF
digitalWrite(RELAY1, LOW);
RELAY1Check = false;
}
}
}
as funções do relay1 está igual a do relay2 mas só o 1 funciona
Se alguém puder ajudar vlw