#define MAX_STATE 4

int ledPin = 12;                // choose the pin for the LED
int greenPin = 11;
int bluePin = 10;
int inputPin = 2;               // choose the input pin (for a pushbutton)
int old_val = 0;
int val = 0;                    // variable for reading the pin status
int state = 0;

int count = 0;
boolean lightOn = true;

void setup() {
  pinMode(ledPin, OUTPUT);      // declare LED as output
  pinMode(greenPin, OUTPUT);      // declare LED as output
  pinMode(bluePin, OUTPUT);      // declare LED as output
  pinMode(inputPin, INPUT);     // declare pushbutton as input

  setState(0);
}

// ALL LED OFF
void allOff(){
  digitalWrite(ledPin, LOW);
  digitalWrite(greenPin, LOW);
  digitalWrite(bluePin, LOW);
}

// ALL LED ON
void allOn(){
  digitalWrite(ledPin, HIGH);
  digitalWrite(greenPin, HIGH);
  digitalWrite(bluePin, HIGH);
}

void setState(int s){

  switch(s){
  case 0:
   // RED
   allOff();
   digitalWrite(ledPin, HIGH);
   break;
  case 1:
   // GREEN
   allOff();
   digitalWrite(greenPin, HIGH);
   break;
  case 2:
   // BLUE
   allOff();
   digitalWrite(bluePin, HIGH);
   break;
  case 3:
   // LED ON OFF
   count = 0;
   lightOn = true;
   allOn();
  }
  state = s;

}

void loop(){
  val = digitalRead(inputPin);  // read input value

  if ((val == HIGH) && (old_val == LOW)) {            // check if the input is HIGH

    int newState = state;
    newState++;
    if(newState >= MAX_STATE){
      newState = 0;
    }

    setState(newState);

    delay(50);
  }

  old_val = val;

  if(state == 3){
    // LED ON OFF
    ++count;
    if( (count%2000) == 0){
      if(lightOn == true){
        lightOn = false;
        allOff();
      }else{
        lightOn = true;
        allOn();
      }
    }
  }
}