// Déclaration des constantes et variables

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

int ValButton = 0;
int ValSensor = 0;
int OldValButton = 0;
int State = 0;


// Initialisation des entrées et sorties

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


// Fonction principale en boucle

void loop() { 
  ValButton = digitalRead(PinButton);
  ValSensor = analogRead(PinSensor);
  delay(10);

  if ((ValButton == HIGH) && (OldValButton == LOW)) {
  State = 1 - State;  
  }

  OldValButton = ValButton;

  if (State == 1) { 
    analogWrite(PinLED, 255 - ValSensor/4);
  }
  else {
    analogWrite(PinLED, 0);
  }
}
