Created
February 1, 2015 08:03
-
-
Save elzup/f864534fe21f98dd60d4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // シリアルポート bps[ビット/秒]で初期化 | |
| #define BAUD_BPS 115200 | |
| #define LED_PIN 13 | |
| void setup(){ | |
| pinMode(LED_PIN, OUTPUT); | |
| Serial.begin(BAUD_BPS); | |
| } | |
| // 繰り返し処理 | |
| void loop(){ | |
| int inputchar; | |
| // シリアルポートより1文字読み込む | |
| inputchar = Serial.read(); | |
| if(inputchar != -1 ){ | |
| // 読み込んだデータが -1 以外の場合 以下の処理を行う | |
| switch(inputchar){ | |
| case 'o': | |
| // 読み込みデータが o の場合 | |
| Serial.print("LED ON\n"); | |
| digitalWrite(LED_PIN, HIGH); | |
| break; | |
| case 'p': | |
| // 読み込みデータが p の場合 | |
| Serial.print("LED OFF\n"); | |
| digitalWrite(LED_PIN, LOW); | |
| break; | |
| } | |
| } else { | |
| // 読み込むデータが無い場合は何もしない | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment