Relay Control: 4 Relays, 4 Pushbuttons

Hi,

To prevent a response to two or more buttons being pressed you can assign each button a binary value

int Button1Val =1;
int Button2Val =2;
int Button3Val =4;
int Button4Val =8:

int ButtonSel = (Button1Val * button1state) + (Button2Val * button2state) + (Button3Val * button3state) + (Button4Val * button4state) ;

So ButtonSel will be unique for any button combination.

Then use switch .. case to interperet your ButtonSel

switch (ButtonSel) 
{ case 1: // statements 
your button 1 relay config
  break; 
  case 2: // statements 
your button 2 relay config
  break; 
  case 4: // statements 
  your button 3 relay config
  break; 
  case 8; // statements 
  your button 4 relay config
  break; 
  default: // statements 
  your output config if any other illegal combination is pressed
}

I hope that makes sense.

Tom.. :slight_smile: