结构部分4
setup()4
loop()5
结构控制7
if(条件判断语句)7
if / else9
for语句11
switch / case语句15
while循环17
do...while19
break20
continue21
return22
goto24
扩展语法25
; 分号25
{}大括号26
Comments(注释)30
Define31
#include33
算数运算符34
= 赋值运算符(单等号)34
赋值运算符(单等号)34
加,减,乘,除35
%(取模)37
比较运算符39
==、!=、、<=、>=(比较运算符)39
布尔运算符40
&&(逻辑与)40
||(逻辑或)41
!(逻辑非)41
指针运算符42
位运算符42
按位与(&)42
按位或(|)44
按位异或(^)47
按位取反 (~)49
bitshift left (<>)50
复合运算符54
++ (increment) / -- (decrement)54
+= , -= , *= , /=55
compound bitwise AND (&=)56
描述56
compound bitwise OR (|=)58
变量部分61
常量61
rue与false(布尔Boolean常量)61
引脚电压定义,HIGH和LOW62
数字引脚(Digital pins)定义,INPUT和OUTPUT63
引脚(Pins)配置为输入(Inputs)63
引脚(Pins)配置为输出(Outputs)64
整数常量64
U & L 格式67
浮点常量67
数据类型68
void68
布尔 boolean69
char71
unsigned char72
byte73
int73
unsigned int75
word(字符)76
long77
unsigned long77
float79
double81
string(字符串)82
Arrays (数组)86
数据类型转换89
char89
byte()90
int()91
word()91
long()92
float()93
变量作用域 & 修饰符94
变量的作用域94
Static96
volatile关键字100
const关键字102
函数部分104
数字 I/O104
pinMode()104
digitalWrite()106
digitalRead()108
模拟 I/O111
analogReference(type)111
analogRead()113
analogWrite()115
高级 I/O118
tone()118
shiftOut()120
shiftIn()126
pulseIn()127
时间129
millis()129
micros()130
delay()132
delayMicroseconds()135
数学运算137
min(x, y)137
max(x,y)139
ABS(X)140
constrain(x,a,b)141
map(value, fromLow, fromHigh, toLow, toHigh)142
pow(base, exponent)145
sqrt(x)145
三角函数146
随机数146
randomSeed(seed)146
random()148
位操作151
lowByte()151
highByte()151
bitRead()152
bitWrite()153
bitSet()154
bitClear()154
bit()155
开关中断156
interrupts()(中断)156
detachInterrupt(interrupt)157
开关中断158
interrupts()(中断)158
noInterrupts()159
结构部分
setup()
在Arduino中程序运行时将首先调用 setup() 函数。用于初始化变量、设置针脚的输出\输入类型、配置串口、引入类库文件等等。每次 Arduino 上电或重启后,setup 函数只运行一次。
示例
int buttonPin = 3;
void setup()
{
Serial.begin(9600);
pinMode(buttonPin, INPUT);
}
void loop()
{
// ...
}
loop()
在 setu