Niveau : Facile
Equipement nécessaire :
1 PC avec l’IDE Arduino ou la version WEB
1 Arduino (Pour l’exemple, j’ai pris le modèle « UNO rev.3 »
3 LED/DEL : Vert/jaune/rouge ou n’importe quelles couleur, à votre choix)
x3 Résistances de : 110 K Ohms (link color : https://www.digikey.fr/fr/resources/conversion-calculators/conversion-calculator-resistor-color-code-5-band)
Cables x3 courts + x1 long
Optionnel :
Shield sans soudures
Shield Prototype
Code :
// variables
int GREEN = 2;
int YELLOW = 3;
int RED = 4;
int DELAY_GREEN = 5000;
int DELAY_YELLOW = 2000;
int DELAY_RED = 5000;void setup() {
pinMode(GREEN, OUTPUT);
pinMode(YELLOW, OUTPUT);
pinMode(RED, OUTPUT);
}void loop() {
green_light();
delay(DELAY_GREEN);
yellow_light();
delay(DELAY_YELLOW);
red_light();
delay(DELAY_RED);}
void green_light()
{
digitalWrite(GREEN, HIGH);
digitalWrite(YELLOW, LOW);
digitalWrite(RED, LOW);
}void yellow_light()
{
digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, HIGH);
digitalWrite(RED, LOW);
}void red_light()
{
digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, LOW);
digitalWrite(RED, HIGH);
}
Ensuite, nous pouvons aller plus loin et faire en sorte de créer un « scanner », ou un chenillard allant dans un sens, puis dans l’autre :
Pensez à ajouter deux câbles & deux LED supplémentaires!!!
Code :
// variables
int GREEN = 2;
int YELLOW = 3;
int RED = 4;
int GREEN = 5;
int WHITE = 6;int DELAY_GREEN = 250;
int DELAY_YELLOW = 250;
int DELAY_RED = 250;
int DELAY_GREEN = 250;
int DELAY_WHITE = 250;void setup() {
pinMode(GREEN, OUTPUT);
pinMode(YELLOW, OUTPUT);
pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(WHITE, OUTPUT);}
void loop() {
GREEN_light();
delay(DELAY_GREEN);
yellow_light();
delay(DELAY_YELLOW);
red_light();
delay(DELAY_RED);
green_light();
delay(DELAY_GREEN);
white_light();
delay(DELAY_WHITE);
white_light1();
delay(DELAY_WHITE);
green_light1();
delay(DELAY_GREEN);
red_light1();
delay(DELAY_RED);
yellow_light1();
delay(DELAY_YELLOW);
GREEN_light1();
delay(DELAY_GREEN);
}void GREEN_light()
{
digitalWrite(GREEN, HIGH);
digitalWrite(YELLOW, LOW);
digitalWrite(RED, LOW);
digitalWrite(GREEN, LOW);
digitalWrite(WHITE, LOW);
}void yellow_light()
{
digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, HIGH);
digitalWrite(RED, LOW);
digitalWrite(GREEN, LOW);
digitalWrite(WHITE, LOW);
}void red_light()
{
digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, LOW);
digitalWrite(RED, HIGH);
digitalWrite(GREEN, LOW);
digitalWrite(WHITE, LOW);
}void green_light()
{
digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, LOW);
digitalWrite(RED, LOW);
digitalWrite(GREEN, HIGH);
digitalWrite(WHITE, LOW);
}void white_light()
{
digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, LOW);
digitalWrite(RED, LOW);
digitalWrite(GREEN, LOW);
digitalWrite(WHITE, HIGH);
}void white_light1()
{
digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, LOW);
digitalWrite(RED, LOW);
digitalWrite(GREEN, LOW);
digitalWrite(WHITE, HIGH);
}void green_light1()
{
digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, LOW);
digitalWrite(RED, LOW);
digitalWrite(GREEN, HIGH);
digitalWrite(WHITE, LOW);
}void red_light1()
{
digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, LOW);
digitalWrite(RED, HIGH);
digitalWrite(GREEN, LOW);
digitalWrite(WHITE, LOW);
}void yellow_light1()
{
digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, HIGH);
digitalWrite(RED, LOW);
digitalWrite(GREEN, LOW);
digitalWrite(WHITE, LOW);
}void GREEN_light1()
{
digitalWrite(GREEN, HIGH);
digitalWrite(YELLOW, LOW);
digitalWrite(RED, LOW);
digitalWrite(GREEN, LOW);
digitalWrite(WHITE, LOW);
}