#includeは、スケッチに外部ライブラリを含めるために使用されます。 これにより、プログラマは、標準Cライブラリ(あらかじめ作成された関数とデータ型のグループ)の大きなグループにアクセスすることができます。また、特にMaple用に書かれたライブラリも利用できます。
利用例
Arduino LiquidCrystal Tutorialのこの例には、LCDディスプレイを制御するためのライブラリが含まれています。
code:sample1.ino
// include the library code:
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("hello, world!");
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis()/1000);
}
#defineのような#include行にはセミコロンはありません。 コンパイラは、追加すると奇妙なエラーメッセージを出力します。 C標準ライブラリ
Mapleに付属している標準のCライブラリはnewlibです。 主な資料は主な参照ページと数学関数のリファレンスページです。 以下は、数値の立方根をとるためにmath.hライブラリをインポートする例です:
code:sample2.ino
void setup() {
// no setup necessary
}
void loop() {
// "cbrt" stands for "cube root"
double cubeRootOf3 = cbrt(3.0);
// prints a number that is approximately the cube root of 3:
SerialUSB.println(cubeRootOf3);
}
このドキュメントはleafLabs, LLC.が執筆し、たま吉が翻訳・一部加筆修正したものです。