第5章 Arduino IDE編程語言參考


第5章 Arduino IDE編程語言參考

 

一、Arduino IDE內置了編程語言參考,可以作為學習參考

二、系統提供的語言參考分為三個方面

  1. 結構Structure;
  2. 變量Variables;
  3. 函數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開源平台上,展示創意,必須掌握的基本語法規則。

  1. 兩個主函數setup(),loop()。
  2. 每句程序末尾加分號。
  3. 區分大小寫。
  4. 區分全角半角。
  5. 函數和變量名以字母或下划線開頭。
  6. 系統的關鍵字不能被用於其他途徑。
  7. 最好每個語句都加上注釋,這是一個良好的編程習慣、

 


免責聲明!

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



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