// DECLARATIONS GLOBALES
int ORANGE = 4;
int VERT = 7;
int ROUGE = 2;
int BLEU = 8;
int JAUNE = 9;
int VIOLET = 10;
//FONCTIONS
void feuvert() {
digitalWrite(VERT, HIGH);
digitalWrite(ORANGE, LOW);
digitalWrite(ROUGE, LOW);
digitalWrite(BLEU, HIGH);
digitalWrite(JAUNE, LOW);
digitalWrite(VIOLET, LOW);
}
void feurouge() {
digitalWrite(ROUGE, HIGH);
digitalWrite(ORANGE, LOW);
digitalWrite(VERT, LOW);
digitalWrite(BLEU, LOW);
digitalWrite(JAUNE, LOW);
digitalWrite(VIOLET, HIGH);
}
void feuorange(unsigned long tms) {
static unsigned long temps_prec = 0;
static int etat = 0;
if (tms - temps_prec >= 200 && etat == 0) {
digitalWrite(ORANGE, HIGH);
digitalWrite(JAUNE, HIGH);
temps_prec = tms;
etat = 1;
}
if (tms - temps_prec >= 200 && etat == 1) {
digitalWrite(ORANGE, LOW);
digitalWrite(JAUNE, LOW);
temps_prec = tms;
etat = 0;
}
digitalWrite(VERT, LOW);
digitalWrite(ROUGE, LOW);
digitalWrite(BLEU, LOW);
digitalWrite(VIOLET, LOW);
}
void gestion_feu(unsigned long tms){
static unsigned long temps_prec = 0;
static int etat = VERT;
static int clignote_orange = 0;
if (tms - temps_prec >= 1000 && etat == VERT) {
feuvert();
temps_prec = tms;
etat = ORANGE;
}
if (tms - temps_prec >= 1000 && etat == ORANGE) {
clignote_orange = 1;
temps_prec = tms;
etat = ROUGE;
}
if (clignote_orange == 1) {
feuorange(tms);
}
if (tms - temps_prec >= 1000 && etat == ROUGE) {
clignote_orange = 0;
feurouge();
temps_prec = tms;
etat = VERT;
}
}
void gestion_feu2(unsigned long tms){
static unsigned long temps_prec = 0;
static int etat = BLEU;
static int clignote_orange = 0;
if (tms - temps_prec >= 1000 && etat == BLEU) {
feuvert();
temps_prec = tms;
etat = JAUNE;
}
if (tms - temps_prec >= 1000 && etat == JAUNE) {
clignote_orange = 1;
temps_prec = tms;
etat = VIOLET;
}
if (clignote_orange == 1) {
feuorange(tms);
}
if (tms - temps_prec >= 1000 && etat == VIOLET) {
clignote_orange = 0;
feurouge();
temps_prec = tms;
etat = BLEU;
}
}
void setup() {
Serial.begin(9600);
//potentio
pinMode(A0, INPUT_PULLUP);
//leds
pinMode(ORANGE, OUTPUT); //orange
pinMode(ROUGE, OUTPUT);//rouge
pinMode(VERT, OUTPUT);//vert
pinMode(BLEU, OUTPUT);
pinMode(JAUNE, OUTPUT);
pinMode(VIOLET, OUTPUT);
}
void loop() {
//déclarations
int val = analogRead(A0);
unsigned long tms = millis();
//prgm
gestion_feu(tms);
gestion_feu2(tms);
}
/*
if (val>0){
feuvert();
tms=feuorange(tms);
feurouge();
}
}
digitalWrite(ORANGE, HIGH);
digitalWrite(VERT, HIGH);
digitalWrite(ROUGE, HIGH);
*/