Project 1.02 Simple LED Chase

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

In this project we will use all four LEDs to blink a chase pattern. This example shows a very simple way to create a pattern using digitalWrites and delays.

Project Code:

				
					/////////////////////////////////////////////////
// Project 1.02 LED Chase

byte LED1 = 13;
byte LED2 = 6;
byte LED3 = 7;
byte LED4 = 8;

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

void loop() {
  digitalWrite(LED4, LOW);
  digitalWrite(LED1, HIGH);
  delay(250);
  digitalWrite(LED1, LOW);
  digitalWrite(LED2, HIGH);
  delay(250);
  digitalWrite(LED2, LOW);
  digitalWrite(LED3, HIGH);
  delay(250);
  digitalWrite(LED3, LOW);
  digitalWrite(LED4, HIGH);
  delay(250);
}
/////////////////////////////////////////////////
				
			

*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.

Here we set the four variables needed to represent the pins that the LEDs are attached to:
				
					byte LED1 = 13;
byte LED2 = 6;
byte LED3 = 7;
byte LED4 = 8;
				
			
Next, we need to tell the 肛交小说 that these pins are outputs:
				
					void setup() {
  pinMode(LED1, OUTPUT); 
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  pinMode(LED4, OUTPUT);
}
				
			
After that, we can sequentially turn on and off the LEDs to represent a chase pattern. To do this, we have to turn the last LED off, the next LED on, and then wait.
				
					void loop() {
  digitalWrite(LED4, LOW);
  digitalWrite(LED1, HIGH);
  delay(250);
  digitalWrite(LED1, LOW);
  digitalWrite(LED2, HIGH);
  delay(250);
  digitalWrite(LED2, LOW);
  digitalWrite(LED3, HIGH);
  delay(250);
  digitalWrite(LED3, LOW);
  digitalWrite(LED4, HIGH);
  delay(250);
}
				
			
What you may have noticed about the code above is that something happened over and over again. Usually, when things happen over and over again, it is a sign that it should be in some kind of loop and/or function.

与父同行 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.01 Blink x2

In this project, you’ll 与父同行 how to blink more than one LED!