#define BGG 3
#define BG 18
#define BD 19
#define BDD 2
#define nbLED 9
byte ledPins[]={4,5,6,7,8,9,10,11,12};
int tempo=200;
int indice=0;
int sens=1;
void setup()
{
pinMode(BGG, INPUT_PULLUP);
pinMode(BG, INPUT_PULLUP);
pinMode(BD, INPUT_PULLUP);
pinMode(BDD, INPUT_PULLUP);
for (int i;i<nbLED;i++)
{
pinMode(ledPins[i], OUTPUT);
digitalWrite(ledPins[i], LOW);
}
attachInterrupt(digitalPinToInterrupt(BGG), pluslent, FALLING);
attachInterrupt(digitalPinToInterrupt(BDD), plusrapid, FALLING);
attachInterrupt(digitalPinToInterrupt(BD), allerdroite, FALLING);
attachInterrupt(digitalPinToInterrupt(BG), allergauche, FALLING);
}
void loop()
{
digitalWrite(ledPins[indice], HIGH);
delay(tempo);
digitalWrite(ledPins[indice], LOW);
indice=indice+sens;
if (indice>=nbLED) indice=0;
if (indice <0) indice =nbLED-1;
}
void allerdroite()
{
sens=1;
}
void allergauche()
{
sens=-1;
}
void pluslent()
{
tempo=tempo+50;
if (tempo > 5000) tempo=5000;
// tempo=min(tempo,5000);
}
void plusrapid()
{
tempo=tempo-50;
if (tempo < 50) tempo=50;
// tempo=max(tempo,50);
}