第5章 Arduino IDE編程語言參考
一、Arduino IDE內置了編程語言參考,可以作為學習參考
二、系統提供的語言參考分為三個方面
- 結構Structure;
- 變量Variables;
- 函數Functions;
三、程序舉例:我們可以參考程序提供的內置示例程序
練習讀程序!
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
} else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}
四、想和計算機進行交流,在Arduino開源平台上,展示創意,必須掌握的基本語法規則。
- 兩個主函數setup(),loop()。
- 每句程序末尾加分號。
- 區分大小寫。
- 區分全角半角。
- 函數和變量名以字母或下划線開頭。
- 系統的關鍵字不能被用於其他途徑。
- 最好每個語句都加上注釋,這是一個良好的編程習慣、