Arduino 2 サンプルスケッチ、シリアル通信
- 作者: 高本孝頼
- 出版社/メーカー: リックテレコム
- 発売日: 2014/02/17
- メディア: 単行本(ソフトカバー)
- この商品を含むブログを見る
Blink.ino
// the setup function runs once when you press reset or power the board void setup() { // initialize digital pin LED_BUILTIN as an output. pinMode(LED_BUILTIN, OUTPUT); } // the loop function runs over and over again forever void loop() { digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second }
- LED_BUILTIN 基板上の「L」と表記されたLEDがD13に接続した代用として使われる。
Serial.ino
void setup() { Serial.begin(9600); } void loop() { Serial.print("*** Arduino test ***"); Serial.println("+++ Uno R3 test +++"); delay(300); }
- Serial.begin - シリアル通信の開始宣言
- 9600 - ボーレート:1秒間に行う変復調の回数
- シリアル画面への表示
- Serial.print
- Serial.println
- Serial.write, Serial.write(val, len)