Created
June 19, 2014 15:15
-
-
Save 4noha/027b74b7e9cefd704d6d 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
| // 変数の定義 | |
| #define MOTOR_PIN 8 | |
| // 初期化 | |
| void setup(){ | |
| pinMode(MOTOR_PIN, OUTPUT); | |
| // シリアルポートを9600 bps[ビット/秒]で初期化 | |
| Serial.begin(9600); | |
| } | |
| // 繰り返し処理 | |
| void loop(){ | |
| int inputchar; | |
| // シリアルポートより1文字読み込む | |
| inputchar = Serial.read(); | |
| if(inputchar != -1 ){ | |
| // 読み込んだデータが -1 以外の場合 以下の処理を行う | |
| if('s' == inputchar){ | |
| // 読み込みデータが o の場合 | |
| Serial.print("Motor ON\n"); | |
| digitalWrite(MOTOR_PIN, HIGH); | |
| delay(5000); | |
| Serial.print("Motor OFF\n"); | |
| digitalWrite(MOTOR_PIN, LOW); | |
| } | |
| } else { | |
| // 読み込むデータが無い場合は何もしない | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment