Project 1.02 Blink x2
In this project, we bring a second LED, LED3, into the mix. Upload this project and watch the LEDs blink in a pattern.
Concepts: setup(), loop(), declare variables, set pin modes, digitalWrite, delay.
Circuits:
Concepts: setup(), loop(), declare variables, set pin modes, digitalWrite, delay.
Circuits:
Like all sketches, this simple sketch includes a setup() and a loop() block. Before the setup() block we declare two variables that refer to the pin numbers for LED1 and LED3:
int LED1 = 13;
int LED3 = 7;
In the setup() block we set both pins to OUTPUT using two pinMode statements:
pinMode(LED1,OUTPUT);
pinMode(LED3,OUTPUT);
In the loop() block we first switch both LEDs on by setting the pins to HIGH using two digitalWrite statements:
void loop(){
digitalWrite(LED1,HIGH);
digitalWrite(LED3,HIGH);
delay(1000);
After a 1-second delay, we turn both LEDs off:
digitalWrite(LED1,LOW);
digitalWrite(LED3,LOW);
delay(1000);
Next, we turn only LED1 on:
digitalWrite(LED1,HIGH);
digitalWrite(LED3,LOW);
delay(1000);
And then switch so that only LED3 is on:
digitalWrite(LED1,LOW);
digitalWrite(LED3,HIGH);
delay(1000);
Finally, we turn both LEDs off for 1 second before the loop() block reaches its closing bracket } and begins again at the top:
digitalWrite(LED1,LOW);
digitalWrite(LED3,LOW);
delay(1000);
}
int LED1 = 13;
int LED3 = 7;
In the setup() block we set both pins to OUTPUT using two pinMode statements:
pinMode(LED1,OUTPUT);
pinMode(LED3,OUTPUT);
In the loop() block we first switch both LEDs on by setting the pins to HIGH using two digitalWrite statements:
void loop(){
digitalWrite(LED1,HIGH);
digitalWrite(LED3,HIGH);
delay(1000);
After a 1-second delay, we turn both LEDs off:
digitalWrite(LED1,LOW);
digitalWrite(LED3,LOW);
delay(1000);
Next, we turn only LED1 on:
digitalWrite(LED1,HIGH);
digitalWrite(LED3,LOW);
delay(1000);
And then switch so that only LED3 is on:
digitalWrite(LED1,LOW);
digitalWrite(LED3,HIGH);
delay(1000);
Finally, we turn both LEDs off for 1 second before the loop() block reaches its closing bracket } and begins again at the top:
digitalWrite(LED1,LOW);
digitalWrite(LED3,LOW);
delay(1000);
}