【发布时间】:2017-05-29 07:17:25
【问题描述】:
我正在尝试使用 HC-05 构建 LED 闪光灯,但遇到了错误。
这是 Arduino 代码:
int data = 0; //Variable for storing received data
void setup()
{
Serial.begin(9600); //Sets the baud for serial data transmission
pinMode(13, OUTPUT); //Sets digital pin 13 as output pin
}
void loop()
{
if(Serial.available()) // Send data only when you receive data:
{
data = Serial.read(); //Read the incoming data & store into data
Serial.print(data); //Print Value inside data in Serial monitor
Serial.print("\n");
if(data == 1) // Checks whether value of data is equal to 1
digitalWrite(13, HIGH); //If value is 1 then LED turns ON
else if(data == 0) // Checks whether value of data is equal to 0
digitalWrite(13, LOW); //If value is 0 then LED turns OFF
}
}
无论我按下或关闭哪个按钮,int数据的值都将保持不变(255)。
我也使用了很多应用,所以我认为这不是应用问题。
【问题讨论】:
-
与HC-05的关系如何?
标签: bluetooth arduino arduino-ide