Arduino 语言常用语句

上传人:ali****an 文档编号:109969405 上传时间:2019-10-28 格式:DOC 页数:13 大小:78.50KB
返回 下载 相关 举报
Arduino 语言常用语句_第1页
第1页 / 共13页
Arduino 语言常用语句_第2页
第2页 / 共13页
Arduino 语言常用语句_第3页
第3页 / 共13页
Arduino 语言常用语句_第4页
第4页 / 共13页
Arduino 语言常用语句_第5页
第5页 / 共13页
点击查看更多>>
资源描述

《Arduino 语言常用语句》由会员分享,可在线阅读,更多相关《Arduino 语言常用语句(13页珍藏版)》请在金锄头文库上搜索。

1、/*Arduino 语言*/结构 voidsetup()初始化变量,管脚模式,调用库函数等 voidloop() 连续执行函数内的语句 功能数字 I/O pinMode(pin, mode) 数字IO口输入输出模式定义函数,pin表示为013, mode表示为INPUT或OUTPUT。 digitalWrite(pin, value) 数字IO口输出电平定义函数,pin表示为013,value表示为HIGH或LOW。比如定义HIGH可以驱动LED。 intdigitalRead(pin) 数字IO口读输入电平函数,pin表示为013,value表示为HIGH或LOW。比如可以读数字传感器。 模

2、拟 I/O intanalogRead(pin) 模拟IO口读函数,pin表示为05(Arduino Diecimila为05,Arduino nano为07)。比如可以读模拟传感器(10位AD,05V表示为01023)。 analogWrite(pin, value) -PWM 数字IO口PWM输出函数,Arduino数字IO口标注了PWM的IO口可使用该函数,pin表示3, 5, 6, 9, 10, 11,value表示为0255。比如可用于电机PWM调速或音乐播放。 扩展 I/O shiftOut(dataPin, clockPin, bitOrder, value) SPI外部IO扩展

3、函数,通常使用带SPI接口的74HC595做8个IO扩展,dataPin为数据口,clockPin为时钟口,bitOrder为数据传输方向(MSBFIRST高位在前,LSBFIRST低位在前),value表示所要传送的数据(0255),另外还需要一个IO口做74HC595的使能控制。 unsigned longpulseIn(pin, value) 脉冲长度记录函数,返回时间参数(us),pin表示为013,value为HIGH或LOW。比如value为HIGH,那么当pin输入为高电平时,开始计时,当pin输入为低电平时,停止计时,然后返回该时间。 时间函数 unsigned longmil

4、lis() 返回时间函数(单位ms),该函数是指,当程序运行就开始计时并返回记录的参数,该参数溢出大概需要50天时间。 delay(ms) 延时函数(单位ms)。 delayMicroseconds(us) 延时函数(单位us)。 数学函数 min(x, y) 求最小值 max(x, y) 求最大值 abs(x) 计算绝对值 constrain(x, a, b) 约束函数,下限a,上限b,x必须在ab之间才能返回。 map(value, fromLow, fromHigh, toLow, toHigh) 约束函数,value必须在fromLow与toLow之间和fromHigh与toHigh之

5、间。 pow(base, exponent) 开方函数,base的exponent次方。 sq(x) 平方 sqrt(x) 开根号 三角函数 sin(rad) cos(rad) tan(rad) 随机数函数 randomSeed(seed) 随机数端口定义函数,seed表示读模拟口analogRead(pin)函数 。 longrandom(max) 随机数函数,返回数据大于等于0,小于max。 longrandom(min, max) 随机数函数,返回数据大于等于min,小于max。 外部中断函数 attachInterrupt(interrupt, , mode) 外部中断只能用到数字IO

6、口2和3,interrupt表示中断口初始0或1,表示一个功能函数,mode:LOW低电平中断,CHANGE有变化就中断,RISING上升沿中断,FALLING下降沿中断。 detachInterrupt(interrupt) 中断开关,interrupt=1 开,interrupt=0 关。 中断使能函数 interrupts() 使能中断 noInterrupts() 禁止中断 串口收发函数 Serial.begin(speed) 串口定义波特率函数,speed表示波特率,如9600,19200等。 intSerial.available() 判断缓冲器状态。 intSerial.read

7、() 读串口并返回收到参数。 Serial.flush() 清空缓冲器。 Serial.print(data) 串口输出数据。 Serial.println(data) 串口输出数据并带回车符。 /*/*Arduino语言库文件*/官方库文件 EEPROM- EEPROM读写程序库 Ethernet- 以太网控制器程序库 LiquidCrystal-LCD控制程序库 Servo- 舵机控制程序库 SoftwareSerial- 任何数字IO口模拟串口程序库 Stepper- 步进电机控制程序库 Wire-TWI/I2C总线程序库 Matrix- LED矩阵控制程序库 Sprite- LED矩阵

8、图象处理控制程序库 非官方库文件 DateTime- a library for keeping track of the current date and time in software. Debounce- for reading noisy digital inputs (e.g. from buttons) Firmata- for communicating with applications on the computer using a standard serial protocol. GLCD- graphics routines for LCD based on theK

9、S0108or equivalent chipset. LCD- controlLCDs(using 8 data lines) LCD 4 Bit- controlLCDs(using 4 data lines) LedControl- for controlling LED matrices or seven-segment displays with aMAX7221orMAX7219. LedControl- an alternative to the Matrix library for driving multipleLEDswith Maxim chips. Messenger-

10、 for processing text-based messages from the computer Metro- help you time actions at regular intervals MsTimer2- uses the timer 2 interrupt to trigger an action every N milliseconds. OneWire- control devices (from Dallas Semiconductor) that use the One Wire protocol. PS2Keyboard- read characters fr

11、om aPS2keyboard. Servo- provides software support for Servo motors on any pins. Servotimer1- provides hardware support for Servo motors on pins 9 and 10 Simple Message System- send messages between Arduino and the computer SSerial2Mobile- send text messages or emails using a cell phone (via AT comma

12、nds over software serial) TextString- handle strings TLC5940- 16 channel 12 bit PWM controller. X10- Sending X10 signals over AC power lines /*/arduino学习笔记4 数据类型有多种类型的变量,如下所述boolean 布尔char 字符byte 字节int 整数unsigned int 无符号整数long 长整数unsigned long 无符号长整数float 浮点double 双字节浮点string 字符串array 数组arduino学习笔记5

13、 Arduuino复合运算符+= , -= , *= , /=Description描述Perform a mathematical operation on a variable with another constant or variable. The += (et al) operators are just a convenient shorthand for the expanded syntax, listed below.对一个变量和另一个参数或变量完成一个数学运算。+=(以及其他)可以缩短语法长度。Syntax语法x += y; / equivalent to the exp

14、ression x = x + y; / 等价于 x = x + y;x -= y; / equivalent to the expression x = x - y; / 等价于 x = x - y;x *= y; / equivalent to the expression x = x * y; / 等价于 x = x * y;x /= y; / equivalent to the expression x = x / y; / 等价于 x = x / y;Parameters参数x: any variable typex:任何变量类型y: any variable type or constanty:任何变量类型或常数Examples范例x = 2;x += 4; / x now contains 6 / x现在为6x -=

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


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

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