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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM