0% found this document useful (0 votes)
30 views4 pages

Project 1 LED Blink

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views4 pages

Project 1 LED Blink

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Project 1: LED Blink

Description:

we start from simple projects. For this lesson we will perform “Arduion blinks
LED”, which is the basic practice for starter. We provide a test code to control
LED to perform blinking effect. In the code, you could set distinct flashing
scene by changing the time of lighting on and off. Power on GND and VCC, the
LED will light on when signal end S is high level, on the contrary, LED will turn
off when signal end S is low level.
Specifications:

 Control interface: digital port


 Working voltage: DC 3.3-5V
 Pin pitch: 2.54mm
 LED display color: white
 Size: 30 * 20mm
 Weight: 3g

材料:
接线:
GND -- GND
SIG -- D13

code:

void setup() {
// initialize digital pin 13 as an output.
pinMode(13, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(13, HIGH); // turn the LED on (HIGH is the
voltage level)
delay(1000); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the
voltage LOW
delay(1000); // wait for a second
}

Test Result:
Upload test code successfully, white LED starts blinking, lights on for 1000ms,
lights off for 1000ms, alternately.
Code Explanation
The code looks long and clutter, but most of which are comment. The
grammar of Arduino is based on C.
Comments generally have two forms of expression:

/* .......*/ : suitable for long paragraph comments

// : suitable for mono line comments


So the code contains the many vital information, such as the author, the
issued agreement, etc.
Most people omit comments, starter should develop a good habit of looking
through code. Firstly, check comments. They contain the provided information
and do help you understand test code quickly. Secondly, form the habit of
writing comments

// the setup function runs once when you press reset or power the
board
void setup() {
// initialize digital pin 13 as an output.
pinMode(13, OUTPUT);
}

According to comments, we will find that author define the D13 pin mode as
digital output in setup() function. Setup() is the basic function of Arduino. It
will execute once in the running of program, usually as definition pin, define
and ensure the variables.

// the loop function runs over and over again forever


void loop() {
digitalWrite(13, HIGH); // turn the LED on (HIGH is the
voltage level)
delay(1000); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the
voltage LOW
delay(1000); // wait for a second
}

Loop() is the necessary function of Arduino, it can run and loop all the time
after “setup()” executes once
In the loop()function, author uses
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(): set the output voltage of pin to high or low level. We make D13
output high level, then the LED lights on.
delay(1000); // wait for a second
Delay function is used for delaying time, 1000ms is 1s, unit is ms
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
Similarly, we make D13 output low level, LED will turn off.
delay(1000); // wait for a second
Delay for 1s, light on LED--keep on 1s--light off LED--stay on 1s, iterate the
process. LED flashes with 1-second interval. What if you want to make LED
flash rapidly? You only need to modify the value of delay block. Reducing the
delay value implies that the time you wait is shorter, that is, flashing rapidly.
Conversely, you could make LED flash slowly.

You might also like