// Déclaration des constantes et variables

const int PinLEDR = 8;
const int PinLEDV = 7;
const int PinLEDB = 2;
const int PinButton = 12;

int ValButton=0;
int OldValButton=0;
int ComptBtn=0;
unsigned long StartTime = 0;
unsigned long DeltaTime = 0;


// Initialisation des entrées et sorties

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


// Fonction principale en boucle

void loop() {  
  ValButton = digitalRead(PinButton);
  delay(10);
  if ((ValButton == HIGH)&& (OldValButton == LOW)) {
    StartTime = millis();
    ComptBtn = ComptBtn +1;
    if (ComptBtn == 4) {
      ComptBtn = 1;
    }
  }

  if ((ValButton == HIGH) && (OldValButton == HIGH)) {
  DeltaTime = millis() - StartTime;
    if (DeltaTime > 500) {
      ComptBtn = 0;
    }
  }

  OldValButton = ValButton;

  switch (ComptBtn) {
    case 1 :
      digitalWrite(PinLEDR, HIGH);
      digitalWrite(PinLEDV, LOW);
      digitalWrite(PinLEDB, LOW);
    break;

  case 2 :
    digitalWrite(PinLEDR, LOW);
    digitalWrite(PinLEDV, HIGH);
    digitalWrite(PinLEDB, LOW);
  break;

  case 3 :
    digitalWrite(PinLEDR, LOW);
    digitalWrite(PinLEDV, LOW);
    digitalWrite(PinLEDB, HIGH);
  break;

  case 0 :
    digitalWrite(PinLEDR, LOW);
    digitalWrite(PinLEDV, LOW);
    digitalWrite(PinLEDB, LOW);
  break;
  }
}
