// Déclaration des constantes et variables

const int PinLED = 11;
const int PinButton = 12;

int ValButton = 0;
int OldValButton = 0;
int State = 0;
int Brightness = 0;
unsigned long StartTime = 0;
unsigned long DeltaTime = 0;


// Initialisation des entrées et sorties

void setup() {  
  pinMode (PinButton, INPUT);
}


// Fonction principale en boucle

void loop() { 
  ValButton = digitalRead(PinButton);
  delay(10);
  if ((ValButton == HIGH) && (OldValButton == LOW)) {
    State=1-State;
    StartTime= millis(); 
  }
  if ((ValButton == HIGH) && (OldValButton == HIGH)) {
    DeltaTime = millis() - StartTime;
    if (State == 1 && DeltaTime > 500) {
      Brightness = Brightness + 1;
      delay(10);
      if (Brightness > 255) {
        Brightness = 0;
      }
    }
  }
  OldValButton = ValButton;
  if (State == 1) { 
    analogWrite(PinLED, Brightness);
  }
  else {
    analogWrite(PinLED, 0);
    Brightness = 0;
  }
}

