1、ARDUINO 编程语法基础,结构,setup() loop(),当项目开始运行时会调用setup()函数 常我们在其中初始化一些变量、引脚状态及一些调用的库等 loop函数是一个循环体,其中的程序将会不断的运行,示例 int buttonPin = 3; void setup() Serial.begin(9600); pinMode(buttonPin, INPUT);void loop() if (digitalRead(buttonPin) = HIGH) serialWrite(H); else serialWrite(L); delay(1000); ,控制结构,if if.els
2、e for switch case while do. while break continue return goto,语法,; (分号 ) (大括号 ) / (胆寒注释) /* */ (多汗注释) #define #include,算术运算符,= (assignment operator) + (addition) - (subtraction) * (multiplication) / (division) % (modulo),比较运算符,= (equal to) != (not equal to)(greater than) = (greater than or equal to),
3、布尔运算符,& (and) | (or) ! (not),指针运算符,* dereference operator & reference operator,位运算符,& (bitwise and) | (bitwise or) (bitwise xor) (bitwise not) (bitshift right),复合运算符,+ (increment) - (decrement) += (compound addition) -= (compound subtraction) *= (compound multiplication) /= (compound division) &= (c
4、ompound bitwise and) |= (compound bitwise or),数值,常量 HIGH | LOW INPUT | OUTPUT|INPUT_PULLUP true | false integer constants floating point constants,数值,数据类型 void boolean char unsigned char byte int unsigned int word long unsigned long float double string - char array String - object array,数值,转换 char()
5、 byte() int() word() long() float(),数值,变量范围与限定符 variable scope static volatile const Utilities sizeof(),函数,数字 I/O pinMode() digitalWrite() digitalRead(),模拟 I/O,analogReference() analogRead() analogWrite() - PWM,高级 I/O,tone() noTone() shiftOut() shiftIn() pulseIn(),时间,millis() micros() delay() delayMicroseconds(),数学,min() max() abs() constrain() map() pow() sqrt(),三角函数,sin() cos() tan(),随机数,randomSeed() random(),位与字节,lowByte() highByte() bitRead() bitWrite() bitSet() bitClear() bit(),外部中断,attachInterrupt() detachInterrupt(),通信,Serial Stream,USB(仅适用于Leonardo、Due、Micro),Keyboard Mouse,