Arduino语法详解_含⽰例详解
Arduino 的程序可以划分为三个主要部分:结构、变量(变量与常量)、函数。
结构部分
⼀、结构
1.1 setup()
1.2 loop()switch语句c语言例子
⼆、结构控制
2.1 if
2.lse
2.3 for
2.4 switch case
2.5 while
2. while
2.7 break
2.8 continue
2.9 return
2.10 goto
三、扩展语法
3.1 ;(分号)
3.2 {}(花括号)
3.3 //(单⾏注释)
3.4 /* */(多⾏注释)
3.5 #define
3.6 #include
四、算数运算符
4.1 =(赋值运算符)
4.2 +(加)
4.3 -(减)
4.4 *(乘)
4.5 /(除)
4.6 %(模)
五、⽐较运算符
5.1 ==(等于)
5.2 !=(不等于)
5.3 <(⼩于)
5.4 >(⼤于)
5.5 <=(⼩于等于)
5.6 >=(⼤于等于)
六、布尔运算符
6.1 &&(与)
6.2 ||(或)
6.3 !(⾮)
七、指针运算符
7.1 * 取消引⽤运算符
7.2 & 引⽤运算符
⼋、位运算符
8.1 & (bitwise and)
8.2 | (bitwise or)
8.3 ^ (bitwise xor)
8.4 ~ (bitwise not)
8.5 << (bitshift left)
8.6 >> (bitshift right)
九、复合运算符
9.1 ++ (increment)
9.2 -- (decrement)
9.3 += (compound addition)
9.4 -= (compound subtraction)
9.5 *= (compound multiplication)
9.6 /= (compound division)
9.6 &= (compound bitwise and)
9.8 |= (compound bitwise or)
变量部分
⼗、常量
10.1 HIGH|LOW(引脚电压定义)
10.2 INPUT|OUTPUT(数字引脚(Digital pins)定义)
10.3 true | false(逻辑层定义)
10.4 integer constants(整数常量)
10.5 floating point constants(浮点常量)
⼗⼀、数据类型
11.1 void
11.2 boolean(布尔)
11.3 char(有号数据类型)
11.4 unsigned char(⽆符号数据类型)
11.5 byte(⽆符号数)
11.6 int(整型)
11.7 unsigned int(⽆符号整型)
11.8 word
11.9 long(长整数型)
11.10 unsigned long(⽆符号长整数型)
11.11 float(浮点型数)
11.12 double(双精度浮点数)
11.13 string(char array/字符串)
11.14 String  object(String类)
11.15 array (数组)
⼗⼆、数据类型转换
12.1 char()
12.2 byte()
12.3 int()
12.4 word()
12.5 long()
12.6 float()
⼗三、变量作⽤域 & 修饰符
13.1 variable scope(变量的作⽤域)
13.2 static(静态变量)
13.3 volatile
13.4 const
⼗四、辅助⼯具
14.1 sizeof()
函数部分
⼗五、数字 I/O
15.1 pinMode()
15.2 digitalWrite()
15.3 digitalRead()
⼗六、模拟 I/O
16.1 analogReference() 16.2 analogRead()
16.3 analogWrite()  PWM ⼗七、⾼级 I/O
17.1 tone()
17.2 noTone()
17.3 shiftOut()
17.4 shiftIn()
17.5 pulseIn()
⼗⼋、时间
18.1 millis()
18.2 micros()
18.3 delay()
18.4 delayMicroseconds()⼗九、数学运算
19.1 min()
19.2 max()
19.3 abs()
19.4 constrain()
19.5 map()
19.6 pow()
19.7 sqrt()
19.8 ceil()
19.9 exp()
19.10 fabs()
19.11 floor()
19.12 fma()
19.13 fmax()
19.14 fmin()
19.15 fmod()
19.16 ldexp()
19.17 log()
19.18 log10()
19.19 round()
19.20 signbit()
19.21 sq()
19.22 square()
19.23 trunc()
⼆⼗、三⾓函数
20.1 sin()
20.2 cos()
20.3 tan()
20.4 acos()
20.5 asin()
20.6 atan()
20.7 atan2()
20.8 cosh()
20.9 degrees()
20.10 hypot()
20.11 radians()
20.12 sinh()
20.13 tanh()
⼆⼗⼀、随机数
21.1 randomSeed()
21.2 random()
⼆⼗⼆、位操作
22.1 lowByte()
22.2 highByte()
22.3 bitRead()
22.4 bitWrite()
22.5 bitSet()
22.6 bitClear()
22.7 bit()
⼆⼗三、设置中断函数
23.1 attachInterrupt()
23.2 detachInterrupt()
⼆⼗四、开关中断
24.1 interrupts()(中断)
24.2 noInterrupts()(禁⽌中断)⼆⼗五、通讯
25.1 Serial
25.1.1 if (Serial)
25.1.2 Serial.available()
25.1.3 Serial.begin()
25.1.d()
25.1.5 Serial.find()
25.1.6 Serial.findUntil()
25.1.7 Serial.flush()