#define LEDRED 9
#define LEDBLUE 10
#define LEDWHITE 11
#define BUTTON_LED 13
#define ANALOGON 50

uint8_t lastButtonState = HIGH;
unsigned long startTime = 0;
unsigned long holdInterval = 1000;                  // how long to hold

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);

  pinMode(LEDRED, OUTPUT); analogWrite(LEDRED, 0);
  pinMode(LEDBLUE, OUTPUT); analogWrite(LEDBLUE, 0);
  pinMode(LEDWHITE, OUTPUT); digitalWrite(LEDWHITE, LOW);
  pinMode(BUTTON_LED, INPUT_PULLUP);
}

void loop() {
  // put your main code here, to run repeatedly:

  uint8_t buttonState = digitalRead(BUTTON_LED);
  if (lastButtonState != buttonState) {             // different states: rising or falling
    if (buttonState == LOW) {
      // normal activation on falling
      digitalWrite(LEDWHITE, !digitalRead(LEDWHITE));
      analogWrite(LEDRED, 0);
      analogWrite(LEDBLUE, 0);
      startTime = millis();                         // start counter for hold
    }
    else {
      // turn off all lights on rising
      // digitalWrite(LEDWHITE, LOW);
      analogWrite(LEDRED, 0);
      analogWrite(LEDBLUE, 0);
    }
    delay(50);
  }
  else {                                            // same states: high or low
    if (buttonState == LOW && millis() - startTime > holdInterval) {
      digitalWrite(LEDWHITE, LOW);
      analogWrite(LEDRED, ANALOGON);
      analogWrite(LEDBLUE, ANALOGON);
    }
    else {
      
    }
  }
  lastButtonState = buttonState;
}
