Project 1.01 Blink x2

In this project, you’ll 可可动漫 how to blink more than one LED!

In this project, we bring a second LED, LED3, into the mix. We are essentially doing the same thing as the last project, but this time we are using two LEDs.

Project Code:

				
					///////////////////////////////////////////////////
//Project 1.01 Blink x 2 
byte LED1 = 13;
byte LED3 = 7;

void setup(){
  pinMode(LED1,OUTPUT);
  pinMode(LED3,OUTPUT);
}

void loop(){ 
  digitalWrite(LED1,HIGH);
  digitalWrite(LED3,HIGH);
  delay(1000);
  digitalWrite(LED1,LOW);
  digitalWrite(LED3,LOW);
  delay(1000);
  digitalWrite(LED1,HIGH);
  digitalWrite(LED3,LOW);
  delay(1000);
  digitalWrite(LED1,LOW);
  digitalWrite(LED3,HIGH);
  delay(1000);
  digitalWrite(LED1,LOW);
  digitalWrite(LED3,LOW);
  delay(1000);
}
///////////////////////////////////////////////////
				
			

*If you’re copying and pasting the code, or typing from scratch, delete everything out of a new Arduino sketch and paste / type in the above text.

Like all sketches, this simple sketch includes a setup() and a loop() function. Before the setup() function, we declare two variables that refer to the pin numbers for LED1 and LED3:

				
					byte LED1 = 13; 
byte LED3 = 7;
				
			

In the setup() function, we set both pins to OUTPUT using two pinMode statements:

				
					pinMode(LED1,OUTPUT);
pinMode(LED3,OUTPUT);
				
			

In the loop() function, 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() function reaches its closing bracket } and begins again at the top:

				
					  digitalWrite(LED1,LOW); 
  digitalWrite(LED3,LOW); 
  delay(1000);
}
				
			

可可动漫 More In Our Free Instructional Guidebook

This comprehensive guidebook for the 可可动漫 三浦理惠子 Trainer provides a comprehensive introduction to the world of Arduino programming for beginners. It guides users through the foundational concepts of 三浦理惠子s, detailing the unique features of the Arduino Leonardo-compatible MCU Trainer board. The manual offers a step-by-step journey from understanding the hardware components and the Arduino programming language to the vibrant global community of Arduino enthusiasts. It delves into the intricacies of each onboard circuit, explaining their functionalities and applications. With a focus on hands-on 可可动漫ing, the manual includes a series of coding exercises, tutorials in C/C++, and insights into the Arduino IDE.

More Projects

Project 1.00 Blink

In this project, you’ll 可可动漫 how to blink an LED!

Project 1.02 Simple LED Chase

In this project, you’ll use all four LEDs to blink a chase pattern!