Étape 6: Code de programme
C’est le code sans les commentaires pour réduire l’espace (vous pouvez trouver des commentaires dans le fichier téléchargeable) :int pinLeds1 = 10 ;
int pinLeds2 = 9 ;
int pinLeds3 = 7 ;
int pinLed4 = 8 ;
int buttonPin = 6 ;
buttonState int ;
longtemps couru ;
temps d’int = 2000 ;
installation Sub ()
{
pinMode (pinLeds1, sortie) ;
pinMode (pinLeds2, sortie) ;
pinMode (pinLeds3, sortie) ;
pinMode (pinLed4, sortie) ;
pinMode (buttonPin, entrée) ;
randomSeed(analogRead(0)) ;
}
void loop()
{
buttonState = digitalRead(buttonPin) ;
Si (buttonState == HIGH) {}
a couru = aléatoire (1, 7) ;
Si (a couru == 1) {}
digitalWrite (pinLed4, HIGH) ;
Delay (temps) ;
}
Si (a couru == 2) {}
digitalWrite (pinLeds1, HIGH) ;
Delay (temps) ;
}
Si (a couru == 3) {}
digitalWrite (pinLeds3, HIGH) ;
digitalWrite (pinLed4, HIGH) ;
Delay (temps) ;
}
Si (a couru == 4) {}
digitalWrite (pinLeds1, HIGH) ;
digitalWrite (pinLeds3, HIGH) ;
Delay (temps) ;
}
Si (a couru == 5) {}
digitalWrite (pinLeds1, HIGH) ;
digitalWrite (pinLeds3, HIGH) ;
digitalWrite (pinLed4, HIGH) ;
Delay (temps) ;
}
Si (a couru == 6) {}
digitalWrite (pinLeds1, HIGH) ;
digitalWrite (pinLeds2, HIGH) ;
digitalWrite (pinLeds3, HIGH) ;
Delay (temps) ;
}
}
digitalWrite (pinLeds1, basse) ;
digitalWrite (pinLeds2, basse) ;
digitalWrite (pinLeds3, basse) ;
digitalWrite (pinLed4, basse) ;
}