预览模式: 普通 | 列表
经典游戏:bloxorz自定义关数升级版(原创首发)

Tags: {34}

分类:杂货铺 | 固定链接 | 评论: 1 | 引用: 0 | 查看次数: 529

for

for statements

Description描述

The for statement is used to repeat a block of statements enclosed in curly braces. An increment counter is usually used to increment and terminate the loop. The for statement is useful for any repetitive operation, and is often used in combination with arrays to operate on collections of data/pins.
for语句用于需要重复循环执行大括号中的代码块的时候。通常使用一个增量来控制继续重复或结束这个循环。for语句可以有效协助我们完成任何重复性的任务,它常用于收集接口数据,并储存到一个数组里。

 

There are three parts to the for loop header:
for循环的头部分为3个部分:

 

for (initialization初始值; condition条件; increment增量) {

//statement(s);
//需要循环执行的任务代码;

查看更多...

Tags: arduino双语手册

分类:arduino双语手册 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 617

if/else

if/else

if/else allows greater control over the flow of code than the basic if statement, by allowing multiple tests to be grouped together. For example, an analog input could be tested and one action taken if the input was less than 500, and another action taken if the input was 500 or greater. The code would look like this:
if/else比基本的if条件语句在代码流动上拥有更多的控制,允许进行多重条件测试,例如,测试一个模拟接口,当其输入的值小于500时将执行一些命令,但当其输入的值等于或大于500时将执行另一些命令。代码如下:

 

if (pinFiveInput < 500)
{
// action A
}
else
{
// action B
}

 

else can proceed another if test, so that multiple, mutually exclusive tests can be run at the same time:
else能进行另一个条件测试。因此,多重的、互斥的测试能够在同一时间被执行。

 

if (pinFiveInput < 500)
{
// do Thing A
}
else if (pinFiveInput >= 1000)
{
// do Thing B
}
else
{
// do Thing C
}

 

You can have an unlimited nuber of such branches. (Another way to express branching, mutually exclusive tests is with the switch case statement.
你能够使用无限数量的这种分支。(也可以使用switch case语句来实现)

 

Coding Note: If you are using if/else, and you want to make sure that some default action is always taken, it is a good idea to end your tests with an else statement set to your desired default behavior.
编码注释:如果你使用 if/else,并且希望任何条件都有相应的动作被执行,一个好方法是在你的条件测试后用else来处理其它条件所需执行的动作。

Tags: arduino双语手册

分类:arduino双语手册 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 541

if

if

if tests whether a certain condition has been reached, such as an input being above a certain number. The format for an if test is:
如果测试的某一个条件被满足,例如测试输入的值是否大于某个值,其格式为:

 

if (someVariable > 50)
{
// do something here
//在这里放置当条件成立时需要执行的命令。 }

 

The program tests to see if someVariable is greater than 50. If it is, the program takes a particular action. Put another way, if the statement in parentheses is true, the statements inside the brackets are run. If not, the program skips over the code.
这个程序都测试某个变量是否大于50.如果为真,程序将执行一些命令。另一种解释是,如果IF语句中小括号里面的语句为真,就执行后面大括号里的语句,否则,就跳过这些代码。

 

The brackets may be omitted after an if statement. If this is done, the next line (defined by the semicolon) becomes the only conditional statement.
IF语句后面的大括号可以被省略。如果这样,紧接着的一行代码(由分号进行划分)将成为唯一的条件语言。

if (x > 120)  digitalWrite(LEDpin, HIGH); 

if (x > 120) digitalWrite(LEDpin, HIGH);

if (x > 120) {digitalWrite(LEDpin, HIGH);} // all are correct
//这些写法都正确。

 

The statements being evaluated inside the parentheses require the use of one or more operators:
在括号内进行比较的语句需要一个或更多的操作符:

 

Operators:操作符

 x == y (x is equal to y)
x != y (x is not equal to y)
x <  y (x is less than y)
x >  y (x is greater than y)
x <= y (x is less than or equal to y)
x >= y (x is greater than or equal to y)

 

Warning: 警告

查看更多...

Tags: arduino双语手册

分类:arduino双语手册 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 577

analogWrite

analogWrite(pin, value)

Description描述

Writes an analog value (PWM wave) to a pin. On newer Arduino boards (including the Mini and BT) with the ATmega168 chip, this function works on pins 3, 5, 6, 9, 10, and 11. Older USB and serial Arduino boards with an ATmega8 only support analogWrite() on pins 9, 10, and 11.
给一个接口写入模拟值(PWM波)。对于 ATmega168芯片的Arduino卡(包括Mini或BT),该函数可以工作于 3, 5, 6, 9, 10和 11号接口。老的 ATmega8芯片的USB和 serial Arduino卡仅仅支持 9, 10和11号接口。

 

Can be used to light a LED at varying brightnesses or drive a motor at various speeds. After a call to analogWrite, the pin will generate a steady wave until the next call to analogWrite (or a call to digitalRead or digitalWrite on the same pin).
能够以不同亮度点亮LED或以不同的速度驱动马达。在一个analogWrite写入之后,该接口将产生一个稳定波值直到下一个analogWrite重新写入(或digitalReaddigitalWrite操作于相同的接口)。

 

Parameters参数

pin: the pin to write to.
pin: 要写入的接口编号。

查看更多...

Tags: arduino双语手册

分类:arduino双语手册 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 772

loop()

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() 函数就正如它名字所示,让你的程序循环地被执行。使用它来运转Arduino卡。

 

Example

int buttonPin = 3;
// setup initializes serial and the button pin
void setup()
{
beginSerial(9600);
pinMode(buttonPin, INPUT);
}
// loop checks the button pin each time,
// and will send serial if it is pressed
void loop()
{
if (digitalRead(buttonPin) == HIGH)
serialWrite('H');
else
serialWrite('L');
delay(1000);
}

Tags: arduino双语手册

分类:arduino双语手册 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 615