// Déclaration des constantes et variables

const int PinLEDR = 11;
const int PinLEDB = 10;
const int PinLEDV = 9;
const int PinPOTR = A2;
const int PinPOTB = A0;
const int PinPOTV = A1;
const int PinButton = 12;

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

int BrightnessR = 0;
int BrightnessB = 0;
int BrightnessV = 0;


// Initialisation des entrées et sorties

void setup() { 
  pinMode (PinLEDR, OUTPUT);
  pinMode (PinLEDB, OUTPUT);
  pinMode (PinLEDV, OUTPUT);
  pinMode (PinButton, INPUT);
}


// Fonction principale en boucle

void loop() {  
  ValButton = digitalRead(PinButton);
  delay(10);
  if ((ValButton == HIGH) && (OldValButton == LOW)) {
    State=1-State;  
  }
  OldValButton = ValButton;
  if (State == 1) {   
    BrightnessR = analogRead(PinPOTR);
    BrightnessB = analogRead(PinPOTB);
    BrightnessV = analogRead(PinPOTV);
    analogWrite(PinLEDR, 255 - BrightnessR/4);
    analogWrite(PinLEDB, 255 - BrightnessB/4);
    analogWrite(PinLEDV, 255 - BrightnessV/4); 
  }
  else {
    analogWrite(PinLEDR, 0);
    analogWrite(PinLEDB, 0);
    analogWrite(PinLEDV, 0);
  }
}
