基础知识
引脚相关
- pinMode(pin, mode)
引脚定义,例如
pinMode(7, INPUT)
将引脚7定义为输入模式
-
digitalWrite(pin, value)
数字IO口输出电平定义函数,需要先经过pinMode(pin, mode) 声明才能生效 -
int digitalRead(pin)
数字IO口读取电平函数 -
int analogRead(pin)
模拟IO口读取函数 -
analogWrite(pin, value)
数字IO口PWM输出函数
时间相关
- unsigned long millis()
程序运行到现在的毫秒数,最大可50天 - delay(ms)
延迟毫秒数 - delayMicroseconds(us)
延迟微妙数
数学函数
- min(x, y)
求最小值,返回最小值 - max(x, y)
求最大值,返回最大值 - constrain(x, a, b)
约束函数,x变量位于a和b之间,小于a返回a,大于b返回b
随机函数
- long random(max)
随机函数,获取到大于等于0,小于max的数
串口函数
- Serial.begin(speed)
串口定义波特率 - int Serial.read()
读串口并返回收到的参数,读取1byte的序列资料 - Serial.print(data)
串口输出数据,默认十进制 - Serial.print(data, encoding)
串口输出数据,提供编码选项,默认十进制 - Serial.println(data)
串口输出数据,跟随一个回车和换行符
官方库文件
- EEPROM - EEPROM读写程序库
- Ethernet - 以太网控制器程序库
- LiquidCrystal - LCD控制程序库
- Servo - 舵机控制程序库
- SoftwareSerial - 任何数字IO口模拟串口程序库
- Stepper - 步进电机控制程序库
- Wire - TWI/I2C总线程序库
- Matrix - LED矩阵控制程序库
- Sprite - LED矩阵图象处理控制程序库
非官方文件
- 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 the KS0108 or equivalent chipset.
- LCD - control LCDs (using 8 data lines)
- LCD 4 Bit - control LCDs (using 4 data lines)
- LedControl - for controlling LED matrices or seven-segment displays with a MAX7221 or MAX7219.
- LedControl - an alternative to the Matrix library for driving multiple LEDs with Maxim chips.
- Messenger - 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 from a PS2 keyboard.
- 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 commands over software serial)
- TextString - handle strings
- TLC5940 - 16 channel 12 bit PWM controller.
- X10 - Sending X10 signals over AC power lines