We will see now the necessaries material for this project:
The resistor is used to protect your leds from a pic of current. If you need to calculate the value of resistor you need , you can find how to do it on our course.
int led_floor_bottom = 11; // We assign the bottom floor of leds at the pins 11.
int led_floor_middle = 10; // We assign the bottom middle of leds at the pins 10.
int led_floor_top = 9; // We assign the top floor of leds at the pins 9.
void setup() {
pinMode(led_floor_bottom, OUTPUT); // We assign the leds of the bottom floor as an output
pinMode(led_floor_middle, OUTPUT); //We assign the leds of the middle floor as an output
pinMode(led_etage_top, OUTPUT); // We assign the leds of the top floor as an output
}
void loop() {
// to blink the bottom floor
digitalWrite(led_floor_bottom,HIGH);
delay(200);
digitalWrite(led_floor_bottom,LOW);
// to blink the middle floor
digitalWrite(led_floor_middle,HIGH);
delay(200);
digitalWrite(led_floor_middle,LOW);
// to blink the top floor
digitalWrite(led_floor_top,HIGH);
delay(200);
digitalWrite(led_floor_top,LOW);
}
Our program permits to blink each floor of the square one by one during 200 ms. Nevertheless this program can be modified for to turn on all the floor in the same time or blink the led quicker of slower by playing with the delay.
This is the simulation of the project on Tinkercad: