arduino 创客教程第一季第一集 arduino sketch文件最小单元

来源:互联网 发布:嵌入式软件有哪些 编辑:程序博客网 时间:2024/05/01 13:05

这个例子包含了让sketchArduino IDE 编译通过所需要的最少代码:setup() 函数和loop()函数

 

本例子需要的硬件设备

arduino uno板

杜邦线

电路搭接



void setup() {  // 这里请写初始化代码,本函数只运行一次。}void loop() {  // 将主要的代码放在这里以重复执行。}



例程解释:

setup()

loop()

setup()

The setup() function is called when a sketch starts. Use it to initialize variables, pin modes, start using libraries, etc. The setup function will only run once, after each powerup or reset of the Arduino board.

setup()函数在工程启动时被调用。你可用它来初始化变量、定义引脚工作模式、初始化代码库(library)等等。setup函数在板子每次通电或重新初始化(reset)后仅被调用一次。

loop()

After creating a setup() function, which initializes and sets the initial values, the loop() function does precisely what its name suggests, and loops consecutively, allowing your program to change and respond. Use it to actively control the Arduino board.

在创建setup()函数之后,loop()函数就会开始“工作”了。恰如其名(loop意为循环),它会不断的被执行。使用loop函数你就可以真正地在运行时使用你的这块Arduino uno板了。工程内loop()函数的代码被用作在运行时控制这块板。

本例也向你展示了如何在代码中进行代码注释

每个以 “//”开头的代码行都不会被编译器读取,因此你可在”//”的后面写任何你想要的东西。当然, “//”也可能会被放在代码行的末尾。像下面这样书写代码注释将会使代码容易理解,并使读者能够一步一步地了解软件运行过程。


setup()点击打开链接

loop()点击打开链接

阅读全文
0 0
原创粉丝点击