Last active
April 25, 2019 16:48
-
-
Save youjunjer/991eaa7e12a66f4cc30b2e3c0bf6b63b to your computer and use it in GitHub Desktop.
ArduinoBluetoothControl
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
#include <BluetoothSerial.h> | |
BluetoothSerial SerialBT;//宣告藍芽物件=SerialBT | |
void setup() { | |
// put your setup code here, to run once: | |
Serial.begin(9600);//序列視窗 | |
SerialBT.begin("BLETEST");//<<藍芽廣播名稱,請自己記得 | |
pinMode(4,OUTPUT);//風扇relay | |
pinMode(16,OUTPUT);//電燈relay | |
} | |
void loop() { | |
if(SerialBT.available()){ | |
Serial.println(""); | |
} | |
while(SerialBT.available()) | |
{ | |
char btdata=SerialBT.read(); | |
Serial.print(btdata);//查看藍芽輸入的值 | |
if (btdata=='1'){digitalWrite(4,HIGH);}//關風扇 | |
if (btdata=='2'){digitalWrite(4,LOW);}//開風扇 | |
if (btdata=='3'){digitalWrite(16,HIGH);}//關電燈 | |
if (btdata=='4'){digitalWrite(16,LOW);}//開電燈 | |
} | |
delay(100); | |
} | |
© 2019 GitHub, Inc. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment