Blink (闪光) - My First Arduino Project (我的第一个微处理器项目)
In this project, you'll learn about the Arduino (微处理器) IDE programming environment (集成开发环境) and how to make a LED light (发光二极管) blink (眨).
Parts needed:
| ||
1 | If the Arduino IDE program has not been installed on your computer, you can click here to download and install (安装) the program. Otherwise, go to step 2. | |
2 |
Double-click on the Arduino icon to start the Arduino IDE program.
Click here if you are using the Arduino Nano instead of the Uno. Click here for fast track (快速通道), or continue on to step 3. | |
3 | Create a new program by selecting File from the menu
| |
4 | You will see this template (模板).
Commands (命令) that you put inside the "Inside" means between the two curly brackets { and }. Commands that you put inside the Lines starting with the two slashes // are comments (评语), and they are ignored (忽视) by the computer. In other words, to save time, you don't need to type anything that follows the two slashes (斜线). Comments (评语) are there to tell you what the code (代码) is doing. | |
5 | There is a built-in (内置) light (LED) (发光二极管) on the Arduino board that is connected (连接) to digital I/O pin 13. | |
6 | To control the LED (发光二极管) we need to issue (发出) two commands (命令) to the Arduino:
First, we use the Second, we use the Type in these two commands inside the A semicolon (分号) is placed after each command line; in this case the | |
7 | Connect your Arduino board to your computer using the USB cable (数据线). | |
8 | From the Arduino IDE (集成开发环境) program menu, select Tools
| |
9 | Press the upload button to upload (上载) the program onto the Arduino board. | |
If the upload is successful (成功) you should see the words Done uploading (上载) at the bottom, and the Arduino will automatically (自动) run the program. You should see the LED on the Arduino board turned on (打开). | ||
If you have selected the wrong COM port or if there are errors (错误) in your program, you will see an orange error message (错误信息) at the bottom. You'll have to correct the error(s) and then upload your program again. | ||
10 | To make the LED blink (闪烁), we need to turn on and then turn off the LED.
To turn off the LED, we use another | |
11 | Upload the program again. Did you see the LED blink? --- NO
You only see the LED off because the Arduino executed (执行) the two | |
12 | To keep the LED on a little longer so that you can see it, we need to use the
The number specified (指定) in the 1000 ms = 1 sec | |
13 | Upload the program again. What do you see? --- The LED turns on for 1 second and then it turns off (关闭). | |
14 | To make the LED blink continuously (持续), we need to keep repeating (重复) the on and off sequence.
To do that, you move the two | |
15 | Upload the program again. What do you see? --- The LED just stays on. Why?
Because there's no delay after the digitalWrite LOW command and the loop goes back right away to the digitalWrite HIGH command. | |
16 | Solution (解决), we need another
| |
17 | Upload the program again. This time you'll see the LED blink on for 1 second and then off for 1 second.
Congratulations (祝贺)! You've completed your first Arduino project to make a LED blink! Now click on the Experiments (实验) button below to test (测试) yourself. | |