Created
February 15, 2013 10:20
-
-
Save shikajiro/4959532 to your computer and use it in GitHub Desktop.
arduinoでbluetoothを動かす。
This file contains 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
//http://umikappa.main.jp/20110708-148 | |
#define LED 13 //デジタルピン13番をLEDという名前にする | |
//初期化メソッド | |
void setup(){ | |
Serial.begin(115200);//シリアルポートは9600bpsに | |
pinMode(LED,OUTPUT);//LEDピンを出力モードに | |
} | |
//繰返し処理されるメインのメソッド | |
void loop(){ | |
int length = Serial.available(); //シリアル入力受信文字数 | |
//シリアルポートにデータがあれば処理する | |
if(length>0){//データがない時は-1で素通り | |
char c=Serial.read();//1文字読み込み | |
digitalWrite(LED,HIGH);//LED点灯 | |
delay(500); //0.5秒待つ | |
digitalWrite(LED,LOW);//LED消灯 | |
delay(500); //0.5秒待つ | |
//受け取った文字をシリアルポートに出力(表示) | |
Serial.println(c); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment