Arduino 语法与函数

Arduino programs can be divided in three main parts: structure, values (variables and constants), and functions.

Structure

•     setup()    每次 Arduino 上电或重启后,setup 函数只运行一次,用于初始化变量、设置针脚的输出输入类型、配置串口、引入类库文件等等

•     loop()     该函数在程序运行过程中不断的循环

Control Structures   结构控制 

•     if

•     if...else

•     for

•     switch case

•     while

•     do... while

•     break

•     continue

•     return

•     goto

Further Syntax    进一步的语法

•     ; (semicolon)

•     { } (curly braces)

•     // (single line comment)

•     /* */ (multi-line comment)

•     #define

•     #include

Arithmetic Operators   数学运算符

•     = (assignment operator)

•     +  (addition)

•     - (subtraction)

•     * (multiplication)

•     / (division)

•     % (modulo)

Comparison Operators  比较运算符 

•     == (equal to)

•     != (not equal to)

•     < (less than)

•     > (greater than)

•     <= (less than or equal to)

•     >= (greater than or equal to)

Boolean Operators    布尔运算符

•     && (and)

•     || (or)

•     ! (not)

Pointer Access Operators    指针运算符 

•     * dereference operator

•     & reference operator

Bitwise Operators    位运算符

•     & (bitwise and)

•     | (bitwise or)

•     ^ (bitwise xor)

•     ~ (bitwise not)

•     << (bitshift left)

•     >> (bitshift right)

Compound Operators    比较运算符 

•     ++ (increment)

•     -- (decrement)

•     += (compound addition)

•     -= (compound subtraction)

•     *= (compound multiplication)

•     /= (compound division)

•     %= (compound modulo)

•     &= (compound bitwise and)

•     |= (compound bitwise or)

Variables

Constants  常量

•     HIGH | LOW

•     INPUT | OUTPUT |INPUT_PULLUP

•     LED_BUILTIN

•     true | false

•     integer constants

•     floating point constants

Data Types  数据类型

•     void

•     boolean

•     char

•     unsigned char

•     byte

•     int

•     unsigned int

•     word

•     long

•     unsigned long

•     short

•     float

•     double

•     string - char array

•     String - object

•     array

Conversion    数据转换

•     char()   转换为字符型

•     byte()   转换为字节型

•     int()      转换为整型

•     word()  

•     long()  转换为长整型

•     float()    转换为实型

Variable Scope & Qualifiers

•     variable scope

•     static

•     volatile

•     const

Utilities

•     sizeof()

•     PROGMEM

Functions

Digital I/O

•     pinMode()      引脚定义

•     digitalWrite()   开关量输入

•     digitalRead()   开关量输出

Analog I/O

•     analogReference()     模拟量参考电压设置

•     analogRead()    模拟量输入

•     analogWrite() - PWM    模拟量输出

Due & Zero only

•     analogReadResolution()

•     analogWriteResolution()

Advanced I/O

•     tone()       方波输出

•     noTone()    方波输出取消

•     shiftOut()    串行数据输出

•     shiftIn()     串行数据输入

•     pulseIn()     输入脉冲的高电平时间长度

Time

•     millis()    程序运行时间,毫秒

•     micros()   程序运行时间,微秒

•     delay()   延时函数,毫秒

•     delayMicroseconds()  延时函数,微秒

Math

•     min()  计算最小值

•     max()  计算最大值

•     abs()   绝对值函数

•     constrain()   变量区间限制

•     map()     区间变换函数

•     pow()    幂函数

•     sqrt()   平方根函数

Trigonometry   三角函数

•     sin()

•     cos()

•     tan()

Characters   字符函数

•     isAlphaNumeric()

•     isAlpha()

•     isAscii()

•     isWhitespace()

•     isControl()

•     isDigit()

•     isGraph()

•     isLowerCase()

•     isPrintable()

•     isPunct()

•     isSpace()

•     isUpperCase()

•     isHexadecimalDigit()

Random Numbers 

•     randomSeed()       随机数端口定义函数

•     random()    产生伪随机数

Bits and Bytes 

•     lowByte()

•     highByte()

•     bitRead()

•     bitWrite()

•     bitSet()

•     bitClear()

•     bit()

External Interrupts 

•     attachInterrupt()    外部中断设置

•     detachInterrupt()   外部中断取消

Interrupts

•     interrupts()      中断使能

•     noInterrupts()   中断禁止

Communication

•     Serial 

•     Stream

USB (32u4 based boards and Due/Zero only)

•     Keyboard

•     Mouse

原文地址:https://www.cnblogs.com/MyAutomation/p/9289809.html