Bare Minimum: 最小代码
The bare minimum of code needed to start an Arduino sketch.
启动Arduino项目所需的最低限度代码。
This example contains the bare minimum of code you need for a sketch to compile properly on Arduino Software (IDE): the setup() method and the loop() method.
此示例包含项目以在Arduino软件(IDE)上正确编译所需的最少代码:setup()方法和loop()方法。
Hardware Required所需硬件
Arduino or Genuino Board
Arduino或Genuino板
Circuit电路图
Only your Arduino or Genuino Board is needed for this example.
本示例仅需要您的Arduino或Genuino开发板。
![5969879be57ed06f75b87ca90106d128.png](https://i-blog.csdnimg.cn/blog_migrate/eee4f0b244d6a6ae84a4342af5b96295.jpeg)
image developed using Fritzing. For more circuit examples, see the Fritzing project page
使用Fritzing开发的图像。有关更多电路示例,请参见Fritzing项目页面
Code 代码解析
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 board.
setup()项目开始时调用该函数。用它来初始化变量,引脚模式,开始使用库等。在每次上电或复位板后,设置功能将只运行一次。
After creating a setup() function, the loop() function does precisely what its name suggests, and loops consecutively, allowing your program to change and respond as it runs. Code in the loop() section of your sketch is used to actively control the board.
创建setup()函数后,loop()函数将(正如其名)执行并且连续循环,从而使您的程序在运行时可以进行更改和响应。loop()项目部分中的代码用于主动控制电路板。
The code below won't actually do anything, but it's structure is useful for copying and pasting to get you started on any sketch of your own. It also shows you how to make comments in your code.
下面的代码实际上不会做任何事情,但是它的结构对于复制和粘贴很有用,可帮助您开始编写自己的任何项目。它还显示了如何在代码中进行注释。
Any line that starts with two slashes (//) will not be read by the compiler, so you can write anything you want after it. The two slashes may be put after functional code to keep comments on the same line. Commenting your code like this can be particularly helpful in explaining, both to yourself and others, how your program functions step by step.
任何以两个斜杠(//)开头的行都不会被编译器读取,因此您可以在其后写任何内容。也可以将两个斜杠放在功能代码之后,让注释保持在同一行上。像这样注释您的代码对于向您自己和他人说明程序的每步的功能特别有用。
Code 代码示例
The bare minimum of code needed to start an Arduino sketch.
启动Arduino项目所需的最小代码。
1. void setup() {
2. // put your setup code here, to run once:把您的设置代码放置于此,它将运行一次。
3. }
4. void loop() {
5. // put your main code here, to run repeatedly:把您的主代码放置于此,它将循环运行。
6. }
// translation from arduino.cc