#define numsLeds 9
void gauche();
void droite();
void fast();
void slow();
volatile int sens=1;
volatile int tempo=1;
#define Deltatempo 100
#define Mintempo 100
#define Maxtempo 3000
int NumPinLed[numsLeds]={4,5,6,7,8,9,10,11,12};
const byte Btn_bgg=2;
const byte Btn_bdd=3;
const byte Btn_bg=18;
const byte Btn_bd=19;
void setup() {
Serial.begin(115200);
for(int i=0;i<numsLeds;i++)
{
pinMode(NumPinLed[i], OUTPUT);
digitalWrite(NumPinLed[i], LOW);
}
pinMode(Btn_bgg, INPUT_PULLUP);
pinMode(Btn_bdd, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(Btn_bgg),fast , RISING);
attachInterrupt(digitalPinToInterrupt(Btn_bdd),slow , RISING);
attachInterrupt(digitalPinToInterrupt(Btn_bg),gauche , FALLING);
attachInterrupt(digitalPinToInterrupt(Btn_bd),droite , FALLING);
}
int indice=0;
void loop() {
digitalWrite(NumPinLed[indice], HIGH);
delay(tempo);
digitalWrite(NumPinLed[indice], LOW);
indice=indice+sens;
if (indice>=numsLeds) indice=0;
if (indice<0) indice=(numsLeds-1);
Serial.println(indice);
//Serial.println(sens);
/// autre chose à faire
}
void gauche()
{
sens=1;
}
void droite()
{
sens=-1;
}
void fast()
{
tempo=tempo-Deltatempo;
if (tempo < Mintempo) tempo=Mintempo;
}
void slow()
{
tempo=tempo+Deltatempo;
if (tempo > Maxtempo) tempo=Maxtempo;
}