UTFT on/off buttons wont work

Hey forumers,
I am trying to make 4 (simple??) buttons, that can switch a relay on or off. You should think that this a easy task, but i cant make it working. i have a if statement for different buttons, but when i switch 1 on, button 2 goes off.. etc. So i can have 1 button on at the time, when i push a other button on the rest go off.
Can someone with some more experience then me, push me in the right direction?

I have a 7" TFT CPLD + Shield +MEGA 2560 from coldtears electronics.

I hope someone can push me in the right direction, thanks!

my code:

#include <UTFT.h>
#include <UTouch.h>
#include <UTFT_Buttons.h>
//#include <UTFT_tinyFAT.h>
//#include <tinyFAT.h>

extern uint8_t SmallFont[];
extern uint8_t BigFont[];


// Remember to change the model parameter to suit your display module!
UTFT    myGLCD(CTE70CPLD,38,39,40,41);
UTouch  myTouch( 6, 5, 4, 3, 2);

// Finally we set up UTFT_Buttons :)
UTFT_Buttons  myButtons(&myGLCD, &myTouch);
// Finally we set up UTFT_tinyFAT :)
//UTFT_tinyFAT myFiles(&myGLCD);

void setup()
{
  //file.initFAT();
   
  myGLCD.InitLCD();
  myGLCD.clrScr();
  myGLCD.setFont(BigFont);
  myGLCD.fillScr(VGA_GRAY);
  
  myTouch.InitTouch();
  myTouch.setPrecision(PREC_HI);
  //myFiles.loadBitmap(30, 100, 300, 300, "power.raw");
  //myFiles.loadBitmap(100, 400, 700, 50,"shutdown.bmp");
  
 /*
  // On / Off button 1
  int Status1;
  Status1 = 0;
  // On / Off button 2
  int Status2;
  Status2 = 0;
  // On / Off button 2
  int Status3;
  Status3 = 0;
  */
}

void loop()

{  
  int but1, but2, but3, but4, but5, but6, butX, butY, pressed_button, x, y;
  int Status1, Status2, Status3, Status4;


  
  // Statusbar UP
  myGLCD.drawRect(0, 1, 798, 40);
  myGLCD.setBackColor(VGA_GRAY);
  myGLCD.print( "=== Header ===",CENTER, 12);
    
  // Statusbar DOWN
  myGLCD.drawRect(0, 439, 798, 479);
  myGLCD.print( "=== Footer ===",CENTER, 450);
  //myGLCD.setBackColor(VGA_GRAY);
  
  
  // Menu
  myButtons.setTextFont(BigFont); 
  myButtons.setButtonColors(VGA_BLACK, VGA_GRAY, VGA_WHITE, VGA_RED, VGA_WHITE);
  but1 = myButtons.addButton(10,    100, 200,  70,  "Relay 1");
  but2 = myButtons.addButton(220,   100, 180,  70, "Relay 2");
  but3 = myButtons.addButton(10,    180, 200,  70,  "Relay 3");
  but4 = myButtons.addButton(220,   180, 180,  70, "Relay 4");
  
  
  //but5 = myButtons.addButton(409, 100, 379,  70, "LED slang");
  myButtons.drawButtons();   
    

  
while (true) 
  {
    if (myTouch.dataAvailable())
    {
      pressed_button = myButtons.checkButtons();
           
      if ((pressed_button==but1) && (Status1 == 0 ))
      {
       myButtons.relabelButton(but1, "ON");
       myButtons.drawButton(but1);
       Status1 = 1;
      }
      else
      {
       myButtons.relabelButton(but1, "OFF");
       myButtons.drawButton(but1);
       Status1 = 0;
      }
       
      if ((pressed_button==but2) && (Status2 == 0 )) {
       myButtons.relabelButton(but2, "ON");
       myButtons.drawButton(but2);
       Status2 = 1;
      }
      else {
       myButtons.relabelButton(but2, "OFF");
       myButtons.drawButton(but2);
       Status2 = 0;
      }
         
      if ((pressed_button==but3) && (Status3 == 0 )) {
       myButtons.relabelButton(but3, "ON");
       myButtons.drawButton(but3);
       Status3 = 1;
      }
      else {
       myButtons.relabelButton(but3, "OFF");
       myButtons.drawButton(but3);
       Status3 = 0;
      }

      if ((pressed_button==but4) && (Status4 == 0 )) {
       myButtons.relabelButton(but4, "ON");
       myButtons.drawButton(but4);
       Status4 = 1;
      }
      else {
       myButtons.relabelButton(but4, "OFF");
       myButtons.drawButton(but4);
       Status4 = 0;
      }   
    }
  }    
}
#include <UTFT.h>
#include <UTouch.h>
#include <UTFT_Buttons.h>
//#include <UTFT_tinyFAT.h>
//#include <tinyFAT.h>

extern uint8_t SmallFont[];
extern uint8_t BigFont[];

// Remember to change the model parameter to suit your display module!
UTFT    myGLCD(CTE70CPLD, 28, 39, 40, 41);
UTouch  myTouch( 6, 5, 4, 3, 2);

// Finally we set up UTFT_Buttons :)
UTFT_Buttons  myButtons(&myGLCD, &myTouch);
// Finally we set up UTFT_tinyFAT :)
//UTFT_tinyFAT myFiles(&myGLCD);

void setup()
{
  //file.initFAT();

  myGLCD.InitLCD();
  myGLCD.clrScr();
  myGLCD.setFont(BigFont);
  myGLCD.fillScr(VGA_GRAY);

  myTouch.InitTouch();
  myTouch.setPrecision(PREC_HI);
  //myFiles.loadBitmap(30, 100, 300, 300, "power.raw");
  //myFiles.loadBitmap(100, 400, 700, 50,"shutdown.bmp"); // <=== Good luck with that! ;)

}

void loop()

{
  int but1, but2, but3, but4, but5, but6, butX, butY, pressed_button, x, y;
  int Status1 = 0, Status2 = 0, Status3 = 0, Status4 = 0; // <== ! You had not initialised these

  // Statusbar UP
  myGLCD.drawRect(0, 1, 798, 40);
  myGLCD.setBackColor(VGA_GRAY);
  myGLCD.print( "=== Header ===", CENTER, 12);

  // Statusbar DOWN
  myGLCD.drawRect(0, 439, 798, 479);
  myGLCD.print( "=== Footer ===", CENTER, 450);
  //myGLCD.setBackColor(VGA_GRAY);

  // Menu
  myButtons.setTextFont(BigFont);
  myButtons.setButtonColors(VGA_BLACK, VGA_GRAY, VGA_WHITE, VGA_RED, VGA_WHITE);
  but1 = myButtons.addButton(10,    100, 200,  70, "Relay 1");
  but2 = myButtons.addButton(220,   100, 180,  70, "Relay 2");
  but3 = myButtons.addButton(10,    180, 200,  70, "Relay 3");
  but4 = myButtons.addButton(220,   180, 180,  70, "Relay 4");


  //but5 = myButtons.addButton(409, 100, 379,  70, "LED slang");
  myButtons.drawButtons();

  while (true)
  {
    if (myTouch.dataAvailable())
    {
      pressed_button = myButtons.checkButtons();

      if (pressed_button == but1)
        if (Status1 == 0 ) {
          myButtons.relabelButton(but1, "ON");
          myButtons.drawButton(but1);
          Status1 = 1;
        }
        else
        {
          myButtons.relabelButton(but1, "OFF");
          myButtons.drawButton(but1);
          Status1 = 0;
        }

      if (pressed_button == but2)
        if (Status2 == 0 ) {
          myButtons.relabelButton(but2, "ON");
          myButtons.drawButton(but2);
          Status2 = 1;
        }
        else {
          myButtons.relabelButton(but2, "OFF");
          myButtons.drawButton(but2);
          Status2 = 0;
        }

      if (pressed_button == but3)
        if (Status3 == 0 ) {
          myButtons.relabelButton(but3, "ON");
          myButtons.drawButton(but3);
          Status3 = 1;
        }
        else {
          myButtons.relabelButton(but3, "OFF");
          myButtons.drawButton(but3);
          Status3 = 0;
        }

      if (pressed_button == but4)
        if (Status4 == 0 ) {
          myButtons.relabelButton(but4, "ON");
          myButtons.drawButton(but4);
          Status4 = 1;
        }
        else {
          myButtons.relabelButton(but4, "OFF");
          myButtons.drawButton(but4);
          Status4 = 0;
        }
    }
  }
}

Look at what your 'if' statements were actually doing the way you had written them.... Because all of them had 2 outcomes, if or else.... one or the other would ALWAYS happen....... But what you actually wanted was those 2 outcomes ONLY for the button it referred to..... Hence the nested 'if' works..... Because only when button 2 is pressed, do you care what the status of button 2 is?? Hope that makes sense.

Regards, Merry Christmas! :smiley:

Graham

Look up Arduino Radio buttons. I'd tell you to download my TFT Extension,but since you are already using the UTFT_Button library, I wouldn't want to confuse you, even though my library is much easier to use (not gloating).

What you can do, is have a small function to turn all the relays off, then only turn on the one you need.

switch(pressed_button)
{
 case but1:
  AllOff();
  // turn on relay 1
  break;

 case but2:
  AllOff();
  // turn on relay 2
  break;


case but3:
  AllOff();
  // turn on relay 3
  break;


 case but4:
  AllOff();
  // turn on relay 4
  break;
}


void AllOff()
{
// turn off all relays
}

If you get chatter from the relays turning on and off, you can add in a little if statement that only goes into the switch statement if the button has changed.

if(pressed_button != lastbutton)
{
  switch(...)
  {
    // blaw
  }
  lastbutton = pressed_button;
}

HazardsMind:
What you can do, is have a small function to turn all the relays off, then only turn on the one you need.

Yes, he could, or he could have used his original code which produced exactly that effect, however I suspect he wanted independent on/off control of 4 relays using 4 buttons....

Graham

Thats not what he had, from the looks of it, the relay was only going to be on for a brief moment.
What you gave is a toggle. press once, turn that relay on, press again to turn it off.

He wants a radio button to where one and only one button is on at a time. pressing another button will turn it on and the others off.

My library has a radio button function and I also contributed an example for tactile button too, in the playground.

Maybe I misunderstood his poor English, but if he wants only one button active and the rest off, his original code did exactly that. Or at least it did when I ran it on my MEGA. And if he wanted independent control of all 4 relays, thats what my code gave him.

Regards,

Graham

@HazardsMind

Since you are here, and since you mention your button library, I have a question for you....

#include <UTFT.h>
#include <UTouch.h>
#include <UTFT_Buttons.h>

UTFT          myGLCD(ITDB32S, 25, 26, 27, 28);
UTouch        myTouch(6, 5, 32, 3, 2);
UTFT_Buttons  myButtons(&myGLCD, &myTouch);

extern uint8_t SmallFont[];

void setup()
{
  int menuButtons[13];
  myGLCD.InitLCD();
  myGLCD.clrScr();
  myGLCD.setFont(SmallFont);
  myTouch.InitTouch();
  myTouch.setPrecision(PREC_MEDIUM);
  menuButtons[10] = myButtons.addButton(  7, 223, 16, 16, "X"); // None selected
  menuButtons[11] = myButtons.addButton( 31, 223, 16, 16, "<"); // -10 (20-29) (10-19) (0-9)
  char symb[] = "0";
  for (int i = 0; i < 10; i++) {
    symb[0] = 48 + i;
    menuButtons[i] = myButtons.addButton(((24 * i) + 55), 223 , 16 , 16 , symb );
  }
  menuButtons[12] = myButtons.addButton(295, 223, 16, 16, ">"); // +10 ( 10-19) (20-29) etc
  myButtons.drawButtons();
}

void loop()
{
}

The example given produces

X < 9 9 9 9 9 9 9 9 9 9 >

which is clearly not the intended outcome, would your library do what I wanted using that syntax or does yours just store pointers too?

Regards,

Graham

You want to number each button as you make it? Ill try something.

This is what the code would look like for a password screen.
3 columns, 4 rows of red boxes with the text centered (auto)

#include <Wire.h>
#include <ITDB02_Touch.h>
#include <ITDB02_Graph16.h>
#include <TFT_Extension_old.h>

// Declare which fonts we will be using
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
//myGLCD(RS,WR,CS,RST,ALE,mode);
ITDB02 myGLCD(A1,A2,A0,A3,A5,ITDB32S);   //
ITDB02_Touch  myTouch(13,10,11,12,A4);

TFT_Extension_old myTFT(&myGLCD, &myTouch);

char * text[4][3] = { 
  {
    "1","2","3"}
  ,
  {
    "4","5","6"}
  ,
  {
    "7","8","9"}
  ,
  {
    "*","0","#"}
};

char Pass[5];
char master[5] = "2651";
int Pcount=0;
int PassCounter=0;

void setup()
{
  myGLCD.InitLCD(LANDSCAPE);
  myGLCD.setFont(SmallFont);
  myTouch.InitTouch(LANDSCAPE);
  myTouch.setPrecision(PREC_MEDIUM);
  myTFT.ExtSetup();
  
  for(int line = 0; line <= 239; line++) // custom background color
  {
    myGLCD.setColor(0, 0, line);//text color White  
    myGLCD.drawLine(0, line, 319, line);
  }
  PassWord_makeButton();
}

void loop()
{
  GetNum();
}

void PassWord_makeButton()
{
  byte B = 0;
  for(int y = 0; y < 300;y+=100)
  {
    for(int x = 0; x < 200; x+=50)
    {
      char *myText = text[x/50][y/100]; 
      myTFT.SetTouchButtonText(B, myText, Big, WHITE);
      myTFT.SetTouchButtonColors(B, GREEN, RED, FILL, ROUNDED);
      B++;
    }
  }
  return;
}

void GetNum() 
{
  char * lastText;
  byte B=0;
  for(int tr = 0; tr < 300; tr+=100)
  {
    for(int tc = 0; tc < 200; tc+=50)
    {
      char *myText = text[tc/50][tr/100];
      
      if(myTFT.TouchButton_Draw((90+tr),(20+tc),(30+tr),(50+tc), B)) // this check to see if any of the buttons were pressed, then it sends the corresponding number to the "check" function
      {
        check(*myText); 
      }
      B++;
    }
  }
}


void check(char pass) 
{
  myGLCD.setFont(BigFont);
  Pass[Pcount] = pass;  //store incoming numbers in an array
  myGLCD.print(Pass,CENTER, 1); // show the password as it is being entered

  if(Pcount == 3)// only when the array is filled, does it check the numbers
  {
    delay(1000);
    if(!strcmp(Pass, master)) // compare the password to the master password
    {
      myGLCD.print("GOOD",CENTER, 1);
      delay(1000);
      myGLCD.print("    ",CENTER, 1);
    }
    else
    {
      myGLCD.print("FAIL",CENTER, 1);
      delay(1000);
      myGLCD.print("    ",CENTER, 1);
    }
    clearPassword(); // Clear the password
  }

  Pcount++;
  if(Pcount > 3) // this ensure the count does not exceed the maximum lenght of the password
  {
    Pcount = 0; 
    PassCounter = 0;
  }
}

void clearPassword()
{
  byte i = 3;
  while(i != 0)
    Pass[i--] = NULL;
}

It must be done with char pointers.

HazardsMind:
You want to number each button as you make it? Ill try something.

Yes, I approached Henning to ask if it was a problem, or could it be made to work that way, he said the reason it behaves the way it does, is because the button only stores the pointer, not the contents of the variable, as such, change the variable, and the change will be reflected across all buttons that use 'symb' as the label.

Cheers,

Graham

bump.

Ah ok, thank you for that.

I think I will have a play with it, because there is no question the features are going to be useful at some point, even though in this instance, it functions in the same way as Henning's library.

Graham

Thank you for the great help Graham, i know my english i crap, but i'll try to do my best xD. But this is exactly what meant, 4+ buttons that can switch 4+ relays. 1 on 1, i bought a house this year and i use a 7" tft to control the lightning in my house. I managed to use 2 arduino's and send the commands wireless to an other arduino, i use 433Mhz transmitter and reciever, this works pretty fine for now. I am very new to the arduino programming, and the if statement in the code was dumb and i was not thinking clear :). but this is very cool! I can post the final code if i am almost done, maybe some improvements.

Merry Christmas! :smiley:

HazardsMind:
Look up Arduino Radio buttons. I'd tell you to download my TFT Extension,but since you are already using the UTFT_Button library, I wouldn't want to confuse you, even though my library is much easier to use (not gloating).

Yes thank you, na i'am no confused thats quick :slight_smile: but maybe tat's what a can build in later(all on/off) and i checked your lib already, its nice that you take the time to share it, but i already put a lot of work in this "design", to switch.

But thank for your help!

You are welcome ;D

It was my understanding that is what you wanted. Glad I could help.

Graham

Hi All,

Can the colours 'colors', be changed to RGB 0-255, if so how?

Also regarding the buttons being labelled 'RELAY 1, RELAY 2', then once pressed stating 'ON', or 'OFF', can it be made to state 'RELAY 1"
' ON '
Or,

'RELAY 1'
' OFF '

Meaning the text 'RELAY 1', is towards the top of the button, and it's status is towards the bottom of the button?

Dizzwold.

Can the colours 'colors', be changed to RGB 0-255, if so how?

You would need to do that with a custom function. You can use this one.

unsigned int RGBto565(byte R, byte G, byte B){ 
  return ( (int(R & 0xF8) << 8) | (int(G & 0xFC) << 3) | (B >> 3) );
}

Also regarding the buttons being labelled 'RELAY 1, RELAY 2', then once pressed stating 'ON', or 'OFF', can it be made to state 'RELAY 1"
' ON '
Or,

'RELAY 1'
' OFF '

Meaning the text 'RELAY 1', is towards the top of the button, and it's status is towards the bottom of the button?

No, his library doesn't support multi-line text within a button.

Hi All,

Hazardsmind, Thank you again for your input and help.

Dizzwold.

Hi All,

Where would i use this piece of code in the sketch?

unsigned int RGBto565(byte R, byte G, byte B){
return ( (int(R & 0xF8) << 8) | (int(G & 0xFC) << 3) | (B >> 3) );
}

What i would like to do if possible, is to have more choice of colours/colors than the VGA offerings;

myButtons.setButtonColors(VGA_BLACK, VGA_GRAY, VGA_WHITE, VGA_RED, VGA_WHITE);

The above equates to (text/symbol colour, inactive colour, border colour, highlight colour, background colour) for the button.

Is it possible?

Dizzwold.

What i would like to do if possible, is to have more choice of colours/colors than the VGA offerings;

Those are merely to get you started with some colors.

You can make your own colors, like this.

#define BLACK 0x0
#define LIGHT_RED 0xFD14
#define RED 0xF800
#define DARK_RED 0x6000
#define LIGHT_ORANGE 0xFF52
#define ORANGE 0xFD00
#define DARK_ORANGE 0xFA80
#define LIGHT_YELLOW 0xFFF4
#define YELLOW 0xD7E0
#define DARK_YELLOW 0xCE40
#define LIGHT_GREEN 0xB7F6
#define GREEN 0x07E0
#define DARK_GREEN 0x0320
#define LIGHT_BLUE 0xA51F
#define BLUE 0x001F
#define DARK_BLUE 0x000C
#define PURPLE 0xF81F
#define CYAN 0x07FF
#define GREY 0x8410
#define WHITE 0xFFFF
#define TRANSPARENT 0xFFFFFFFF

In the UTFT library, you are given both options to enter colors.

void setColor(byte r, byte g, byte b);
void setColor(word color);

However for the functions that require only 565 colors, you can use the function in place of the color and enter the RGB color values.

As for using the RGBto565 function,
myButtons.setButtonColors(VGA_BLACK, RGBto565(100,100,200), VGA_WHITE, RGBto565(200,0,100), VGA_WHITE);

Hi all,

HazardsMind, thank you again and your patients, but as i'm only just starting out with code, i'm a bit lost with what you say.

With the code below, that i've begged, borrowed and attempted to fill some of the blanks 'writing in my own uses'. As you can tell, i'm still learning and i apologise for the lack of comments.

Could you give me an example of what you say regarding the line;

myButtons.setButtonColors(VGA_BLACK, VGA_GRAY, VGA_WHITE, VGA_RED, VGA_WHITE);

My code so far

Dizzwold;

/* Arduino 2560, TFT Touch Screen with ILI9327 Controller and 8x Relay Board.
This is a mix of a few examples i've found, and put together, with reference and thanks to;
Henning Karlsen, http://electronics.henningkarlsen.com/
Terry King http://arduino-info.wikispaces.com/ */


#include <UTFT.h>
#include <UTouch.h>
#include <UTFT_Buttons.h>

#define RELAY_ON 0
#define RELAY_OFF 1
#define Relay_1  8       // Reley digital pin#
//#define Relay_1  42    // Relays 1-4 on I/O pins 8-11 for test purposes, Relays 1-8 on I/O pins 42-49 for after testing
#define Relay_2  9       // Waiting for some extended connectors to free-up some I/O pins
//#define Relay_2  43
#define Relay_3  10
//#define Relay_3  44
#define Relay_4  11
//#define Relay_4  45
//#define Relay_5  46
//#define Relay_6  47
//#define Relay_7  48
//#define Relay_8  49

extern uint8_t SmallFont[];
extern uint8_t BigFont[];

// Remember to change the model parameter to suit your display module!
UTFT    myGLCD(ILI9327, 38, 39, 40, 41);
UTouch  myTouch( 6, 5, 4, 3, 2);

// Finally we set up UTFT_Buttons :)
UTFT_Buttons  myButtons(&myGLCD, &myTouch);


void setup()
{

digitalWrite(Relay_1, RELAY_OFF);   //Switch all relay OFF at start or reset
digitalWrite(Relay_2, RELAY_OFF);
digitalWrite(Relay_3, RELAY_OFF);
digitalWrite(Relay_4, RELAY_OFF);
//digitalWrite(Relay_5, RELAY_OFF);
//digitalWrite(Relay_6, RELAY_OFF);
//digitalWrite(Relay_7, RELAY_OFF);
//digitalWrite(Relay_8, RELAY_OFF);


pinMode(Relay_1, OUTPUT);    //Set pins as outputs
pinMode(Relay_2, OUTPUT);
pinMode(Relay_3, OUTPUT);
pinMode(Relay_4, OUTPUT);
//pinMode(Relay_5, OUTPUT);
//pinMode(Relay_6, OUTPUT);
//pinMode(Relay_7, OUTPUT);
//pinMode(Relay_8, OUTPUT);

myGLCD.InitLCD();
myGLCD.clrScr();
myGLCD.setFont(SmallFont);
myGLCD.fillScr(VGA_BLACK);

myTouch.InitTouch();
myTouch.setPrecision(PREC_HI);

}

void loop()

{
int but1, but2, but3, but4, but5, but6, but7, but8, but9, but10, but11, but12, butX, butY, pressed_button, x, y;
int Status1 = 0, Status2 = 0, Status3 = 0, Status4 = 0, Status5 = 0, Status6 = 0, Status7 = 0, Status8 = 0, Status9 = 0, Status10 = 0;


// Menu
myButtons.setTextFont(SmallFont);
myButtons.setButtonColors(VGA_WHITE, VGA_WHITE, VGA_LIME, VGA_RED, VGA_PURPLE );
but1 = myButtons.addButton(10,    10, 80,  70, "# 1 OFF");
but2 = myButtons.addButton(110,   10, 80,  70, "# 2 OFF");
but3 = myButtons.addButton(210,   10, 80,  70, "# 3 OFF");
but4 = myButtons.addButton(310,   10, 80,  70, "# 4 OFF");

but5 = myButtons.addButton(10,    100, 80,  70, "# 5 OFF");
but6 = myButtons.addButton(110,   100, 80,  70, "# 6 OFF");
but7 = myButtons.addButton(210,   100, 80,  70, "# 7 OFF");
but8 = myButtons.addButton(310,   100, 80,  70, "# 8 OFF");
//but9 = myButtons.addButton(220,   180, 180,  70, "# 9 OFF");

myButtons.drawButtons();

while (true)
{
if (myTouch.dataAvailable())
{
pressed_button = myButtons.checkButtons();

if (pressed_button == but1)
if (Status1 == 0 ) {

myButtons.relabelButton(but1, "#1 ON");
myButtons.drawButton(but1);
Status1 = 1;
digitalWrite(Relay_1, RELAY_ON);
}
else
{

myButtons.relabelButton(but1, "#1 OFF");
myButtons.drawButton(but1);
Status1 = 0;
digitalWrite(Relay_1, RELAY_OFF);
}

if (pressed_button == but2)
if (Status2 == 0 ) {
myButtons.relabelButton(but2, "# 2 ON");
myButtons.drawButton(but2);
Status2 = 1;
digitalWrite(Relay_2, RELAY_ON);
}
else {
myButtons.relabelButton(but2, "# 2 OFF");
myButtons.drawButton(but2);
Status2 = 0;
digitalWrite(Relay_2, RELAY_OFF);
}

if (pressed_button == but3)
if (Status3 == 0 ) {
myButtons.relabelButton(but3, "# 3 ON");
myButtons.drawButton(but3);
Status3 = 1;
digitalWrite(Relay_3, RELAY_ON);
}
else {
myButtons.relabelButton(but3, "# 3 OFF");
myButtons.drawButton(but3);
Status3 = 0;
digitalWrite(Relay_3, RELAY_OFF);
}

if (pressed_button == but4)
if (Status4 == 0 ) {
myButtons.relabelButton(but4, "# 4 ON");
myButtons.drawButton(but4);
Status4 = 1;
digitalWrite(Relay_4, RELAY_ON);
}
else {
myButtons.relabelButton(but4, "# 4 OFF");
myButtons.drawButton(but4);
Status4 = 0;
digitalWrite(Relay_4, RELAY_OFF);
}

if (pressed_button == but5)
if (Status5 == 0 ) {
myButtons.relabelButton(but5, "# 5 ON");
myButtons.drawButton(but5);
Status5 = 1;
//digitalWrite(Relay_5, RELAY_ON);
}
else {
myButtons.relabelButton(but5, "# 5 OFF");
myButtons.drawButton(but5);
Status5 = 0;
//digitalWrite(Relay_5, RELAY_OFF);
}
if (pressed_button == but6)
if (Status6 == 0 ) {
myButtons.relabelButton(but6, "# 6 ON");
myButtons.drawButton(but6);
Status6 = 1;
//digitalWrite(Relay_6, RELAY_ON);
}
else {
myButtons.relabelButton(but6, "# 6 OFF");
myButtons.drawButton(but6);
Status6 = 0;
//digitalWrite(Relay_6, RELAY_OFF);
}
if (pressed_button == but7)
if (Status7 == 0 ) {
myButtons.relabelButton(but7, "# 7 ON");
myButtons.drawButton(but7);
Status7 = 1;
//digitalWrite(Relay_7, RELAY_ON);
}
else {
myButtons.relabelButton(but7, "# 7 OFF");
myButtons.drawButton(but7);
Status7 = 0;
//digitalWrite(Relay_7, RELAY_OFF);
}
if (pressed_button == but8)
if (Status8 == 0 ) {
myButtons.relabelButton(but8, "# 8 ON");
myButtons.drawButton(but8);
Status8 = 1;
//digitalWrite(Relay_8, RELAY_ON);
}
else {
myButtons.relabelButton(but8, "# 8 OFF");
myButtons.drawButton(but8);
Status8 = 0;
//digitalWrite(Relay_8, RELAY_OFF);
}
if (pressed_button == but9)
if (Status9 == 0 ) {
myButtons.relabelButton(but9, "# 9 ON");
myButtons.drawButton(but9);
Status9 = 1;
}
else {
myButtons.relabelButton(but9, "# 9 OFF");
myButtons.drawButton(but9);
Status9 = 0;
}
if (pressed_button == but10)
if (Status10 == 0 ) {
myButtons.relabelButton(but10, "# 10 ON");
myButtons.drawButton(but10);
Status10 = 1;
}
else {
myButtons.relabelButton(but10, "# 10 OFF");
myButtons.drawButton(but10);
Status10 = 0;
}
}
}
}





/code]