arduino语法手册资料

上传人:E**** 文档编号:100948742 上传时间:2019-09-25 格式:DOC 页数:74 大小:158KB
返回 下载 相关 举报
arduino语法手册资料_第1页
第1页 / 共74页
arduino语法手册资料_第2页
第2页 / 共74页
arduino语法手册资料_第3页
第3页 / 共74页
arduino语法手册资料_第4页
第4页 / 共74页
arduino语法手册资料_第5页
第5页 / 共74页
点击查看更多>>
资源描述

《arduino语法手册资料》由会员分享,可在线阅读,更多相关《arduino语法手册资料(74页珍藏版)》请在金锄头文库上搜索。

1、Arduino 语法手册Arduino 的程序可以划分为三个主要部分:结构、变量(变量与常量)、函数。69结构部分一、结构1.1 setup()1.2 loop()二、结构控制2.1 if2.2 if.else2.3 for2.4 switch case2.5 while2.6 do. while2.7 break2.8 continue2.9 return2.10 goto三、扩展语法3.1 ;(分号)3.2 (花括号)3.3 /(单行注释)3.4 /* */(多行注释)3.5 #define3.6 #include四、算数运算符4.1 =(赋值运算符)4.2 +(加)4.3 -(减)4.4

2、 *(乘)4.5 /(除)4.6 %(模)五、比较运算符5.1 =(等于)5.2 !=(不等于)5.3 (大于)5.5 =(大于等于)六、布尔运算符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 right)九、复合运算符9.1 + (increment)9.2 - (decrement)9.3 += (compound addition)9.4 -=

3、(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(浮点常量)十一、数据类型1

4、1.1 void11.2 boolean(布尔)11.3 char(有号数据类型)11.4 unsigned char(无符号数据类型)11.5 byte(无符号数)11.6 int(整型)11.7 unsigned int(无符号整型)11.8 word11.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()

5、12.2 byte()12.3 int()12.4 word()12.5 long()12.6 float()十三、变量作用域 & 修饰符13.1 variable scope(变量的作用域)13.2 static(静态变量)13.3 volatile13.4 const十四、辅助工具14.1 sizeof()函数部分十五、数字 I/O15.1 pinMode()15.2 digitalWrite()15.3 digitalRead()十六、模拟 I/O16.1 analogReference()16.2 analogRead()16.3 analogWrite() PWM十七、高级 I/O1

6、7.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

7、.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

8、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(

9、)25.1.4 Serial.end()25.1.5 Serial.find()25.1.6 Serial.findUntil()25.1.7 Serial.flush()25.1.8 Serial.parseFloat()25.1.9 Serial.parseInt()25.1.10 Serial.peek()25.1.11 Serial.print()25.1.12 Serial.println()25.1.13 Serial.read()25.1.14 Serial.readBytes()25.1.15 Serial.readBytesUntil()25.1.16 Serial.setT

10、imeout()25.1.17 Serial.write()25.1.18 Serial.SerialEvent()25.2 Stream二十六、USB(仅适用于 Leonardo 和 Due)26.1 Mouse(键盘)26.2 Keyboard(鼠标)结构部分一、结构1.1 setup()在Arduino中程序运行时将首先调用 setup() 函数。用于初始化变量、设置针脚的输出输入类型、配置串口、引入类库文件等等。每次 Arduino 上电或重启后,setup 函数只运行一次。示例int buttonPin = 3;void setup() Serial.begin(9600); pin

11、Mode(buttonPin, INPUT);void loop() / .1.2 loop()在 setup() 函数中初始化和定义了变量,然后执行 loop() 函数。顾名思义,该函数在程序运行过程中不断的循环,根据一些反馈,相应改变执行情况。通过该函数动态控制 Arduino 主控板。示例int buttonPin = 3; / setup 中初始化串口和按键针脚. void setup() beginSerial(9600); pinMode(buttonPin, INPUT); / loop 中每次都检查按钮,如果按钮被按下,就发送信息到串口void loop() if (digit

12、alRead(buttonPin) = HIGH) serialWrite(H); else serialWrite(L); delay(1000);二、结构控制2.1 ifif(条件判断语句)和 =、!=、(比较运算符)if 语句与比较运算符一起用于检测某个条件是否达成,如某输入值是否在特定值之上等。if 语句的语法是:if (someVariable 50) / 执行某些语句本程序测试 someVariable 变量的值是否大于 50。当大于 50 时,执行一些语句。换句话说,只要 if 后面括号里的结果(称之为测试表达式)为真,则执行大括号中的语句(称之为执行语句块);若为假,则跳过大括

13、号中的语句。 if 语句后的大括号可以省略。若省略大括号,则只有一条语句(以分号结尾)成为执行语句。if (x 120) digitalWrite(LEDpin, HIGH); if (x 120)digitalWrite(LEDpin, HIGH); if (x 120) digitalWrite(LEDpin, HIGH); if (x 120) digitalWrite(LEDpin1, HIGH); digitalWrite(LEDpin2, HIGH); / 以上所有书写方式都正确在小括号里求值的表达式,需要以下操作符:比较运算操作符: x = y(x 等于 y) x != y(x

14、不等于 y) x y(x 大于 y) x = y(x 大于等于 y)警告:注意使用赋值运算符的情况(如 if (x = 10))。一个“=”表示的是赋值运算符,作用是将 x 的值设为 10(将值 10 放入 x 变量的内存中)。两个“=”表示的是比较运算符(如 if (x = 10)),用于测试 x 和 10 是否相等。后面这个语句只有 x 是 10 时才为真,而前面赋值的那个语句则永远为真。这是因为 C 语言按以下规则进行运算 if (x=10):10 赋值给 x(只要非 0 的数赋值的语句,其赋值表达式的值永远为真),因此 x 现在值为 10。此时 if 的测试表达式值为 10,该值永远为真,因为非 0 值永远为真。所以,if (x = 10) 将永远为真,这就不是我们运行

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 高等教育 > 大学课件

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号