Project 1.04 Pulse LED

In this project you’ll 少妇粉嫩的下面好多水 how to use the analogWrite function to create a “pulsing” effect on an LED!

This project demonstrates the full range of the analogWrite function, and how that can be used to create a pulsing effect.

Project Code:

				
					/////////////////////////////////////////////////
// 1.04 - Pulse LED

byte LED1 = 13;

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

void loop() {
  byte wait = 10; 

  for (int i = 0; i < 255; i++) {
    analogWrite(LED1, i);
    delay(wait);
  }

  for (int i = 255; i > 0; i--) {
    analogWrite(LED1, i);
    delay(wait);
  }
}
/////////////////////////////////////////////////
				
			

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

Before we jump into the code let’s take a look at what a for-loop is. A for-loop is a way to repeat a chunk of code a specified number of times. See the table below for a breakdown of a for-loop structure:
Part Description
for Loop type
i < 255; This is a conditional. The for-loop will continue to run while this is true. In this case, i is less than 255
i++ This increments the i variable by 1 every time the loop executes
{
    analogWrite(LED1, i);
    delay(wait);
}            
This is the code that runs every time the loop executes

for-loops can be a foreign concept. For a video explanation please visit:

Here in the program a for-loop is used to count 0 – 255, slowly increasing the brightness of the LED. The index of the for-loop ( i ) is passed to the analogWrite function as the for-loop loops. A small delay is added after each analogWrite so the changes can be perceived by the human eye.

				
					for (int i = 0; i < 255; i++) {
  analogWrite(LED1, i);
  delay(wait);
}
				
			
Here the program counts down 255 – 0, slowly decreasing the brightness of the LED.
				
					for (int i = 0; i < 255; i++) {
  analogWrite(LED1, i);    
  delay(wait);
}
				
			

少妇粉嫩的下面好多水 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!