文档库 最新最全的文档下载
当前位置:文档库 › Arduino 语法手册

Arduino 语法手册

Arduino 的程序可以划分为三个主要部分:结构、变量(变量与常量)、函数

结构部分

setup()
loop()
结构控制

if
if...else
for
switch case
while
do... while
break
continue
return
goto
扩展语法

;(分号)
{}(花括号)
//(单行注释)
/* */(多行注释)
#define
(单词代值)
#include
(头文件)
算数运算符

=(赋值运算符)
+(加)
-(减)
*(乘)
/(除)
%(模)
比较运算符

==(等于)
!=(不等于)
<(小于)
>(大于)
<=(小于等于)
>=(大于等于)
布尔运算符

&&(与)
||(或)
!(非)
指针运算符

* 取消引用运算符
& 引用运算符
位运算符

& (bitwise and)
| (bitwise or)
^ (bitwise xor)
~ (bitwise not)
<< (bitshift left)
>> (bitshift right)
复合运算符

++ (increment)
-- (decrement)
+= (compound addition)
-= (compound subtraction)
*= (compound multiplication)
/= (compound division)
&= (compound bitwise and)
|= (compound bitwise or)
变量部分

常量

HIGH|LOW
INPUT|OUTPUT
true | false
integer constants
floating point constants
数据类型

void
boolean
char
unsigned char
byte
(字节)
int
(整型)
unsigned int
(无符号整型)
word
long
(长整型)
unsigned long
float
(浮点型)
double
(双精度浮点)
string - char array
String - object
array -(数组)
数据类型转换

char()
byte()
int()
word()
long()
float()
变量作用域 & 修饰符

variable scope
static
(静态)
volatile
const
辅助工具

sizeof()
函数部分

数字 I/O

pinMode()
digitalWrite()
digitalRead()
模拟 I/O

analogReference()
analogRead()
analogWrite() - PWM
高级 I/O

tone()
//发声(引脚,频率)
noTone()
//停止发声
shiftOut()
shiftIn()
pulseIn()
时间

millis()
//毫秒记时
micros()
//微秒记时
delay()
//毫秒延时
delayMicroseconds()
//微秒延时
数学运算

min()
//取小值
max()
//取大值
abs()
constrain()
map()
pow()
sqrt()
ceil()–
exp()–
fabs()–
floor()–
fma()–
fmax()–
fmin()–
fmod()–
ldexp()–
log()–
log10()–
round()–
signbit()–
sq()–
square()–
trunc()–
三角函数

sin()
//将弧度转y值
cos()
tan()
acos()–
asin()–
atan()–
atan2()–
cosh()–
degrees()–
hypot()–
radians()–
sinh()–
tanh()–
随机数

randomSeed()
random()
位操作

lowByte()
highByte()
bitRead()
bitWrite()
bitSet()
bitClear()
bit()
设置中断函数

attachInterrupt()
detachInterrupt()
开关中断

interrupts()
noInterrupts()
通讯

Serial
Stream
USB(仅适用于 Leonardo 和 Due)

键盘
鼠标

相关文档