控制板與程式設計入門
1. 關於Arduino Uno控制板
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
2. Arduino 程式基礎
2-1 setup和loop函式
Arduino程式都是由setup和loop所組成,而這兩者正式名稱為函式(funtion)(函式就是一段程式碼的集合。)以下是最基本的Arduino程式:
控制板每次重啟會執行一次setup()大括號中的程式,然後再執行loop()內的程式。
- setup()作用為設定程式參數,且setup()只會被執行一次
- loop()裡的程式敘述將被不停重複執行,直到電源關閉為止。
Arduino 程式可由五個部分組成 :
- 匯入函式庫與定義 (可有可無)
#include <SoftEasyTranfer.h>
#define LEDPIN 13;
- 宣告常數與全域變數 (可有可無)
const float PI=3.14159;
int r;
- 設定函式 (必要)
void setup() {}
- 無限迴圈 (必要)
void loop() {}
- 自訂函式 (可有可無)
float area(float r) {
float a=PIrr;
return a;
}
資源
http://yhhuang1966.blogspot.com/2015/09/arduino_14.html
課本練習P.094