exit if statement

Hi All,

Im trying to make one button to control the heat setting of a heated seat.

I want the button to show off as default, then first press change colour and text, second press change colour again and text, third press back to default of off.

The code below goes through the correct sequence but all the way through on one press, i have tried using a delay to see if i was holding the button too long but this has had no effect.

Can someone help me create a button with like a switch statement?

Cheers
Ryan

if ((x>=10) && (x<=96.6) && (y>=40) && (y<=110)) // Button: Heated Seat
{
if (HeatedSeat1 == 0)
{
myGLCD.setColor(0, 255, 0);
myGLCD.fillRoundRect (10, 40, 96.6, 110);
myGLCD.setColor(0, 0, 0);
myGLCD.setBackColor(0, 255, 0); // heated seat button
myGLCD.drawRoundRect (10, 40, 96.6, 110);
myGLCD.print(“LOW”, 15, 45);

HeatedSeat1++;
delay(100);
}

if (HeatedSeat1 == 1)
{
myGLCD.setColor(255, 0, 0);
myGLCD.fillRoundRect (10, 40, 96.6, 110);
myGLCD.setColor(0, 0, 0);
myGLCD.setBackColor(0, 255, 0); // heated seat button
myGLCD.drawRoundRect (10, 40, 96.6, 110);
myGLCD.print(“HIGH”, 15, 45);

HeatedSeat1++;
delay(100);
}

if (HeatedSeat1 == 2)
{
myGLCD.setColor(0, 0, 255);
myGLCD.fillRoundRect (10, 40, 96.6, 110);
myGLCD.setColor(0, 0, 0);
myGLCD.setBackColor(255, 255, 255); // heated seat button
myGLCD.drawRoundRect (10, 40, 96.6, 110);
myGLCD.print(“OFF”, 15, 45);

HeatedSeat1 = 0;
delay(100);
}
delay(500);

}

You can put 'else' between the 'if' statements so only one executes.

Well why not use a switch statement?

switch (HeatedSeat1) {
  case 0:
    myGLCD.setColor(0, 255, 0);
    myGLCD.fillRoundRect (10, 40, 96.6, 110);
    myGLCD.setColor(0, 0, 0);  
    myGLCD.setBackColor(0, 255, 0);       // heated seat button
    myGLCD.drawRoundRect (10, 40, 96.6, 110);
    myGLCD.print("LOW", 15, 45);
            
    HeatedSeat1++;
    delay(100);
    break;

  case 1:
     ...
}

Just remember the break; statement at the end of each case.

Thanks for the advice, I have put 'else if' for my last two if statements and this has solved it.

Cheers