带有Arduino的HC 05蓝牙模块

时间:2020-02-18 06:15:33

标签: arduino arduino-uno hc-05

我想知道执行“ Bluetooth.available();”的方法 如果连接可用,则需要多少时间,如果连接不可用,则要花费多少时间。

Bluetooth.read(); Bluetooth.println(“ LED On!”);

需要多少时间。

我的项目是时间敏感的,所以问。友善的帮助

我的代码的一部分:::::::

     #include <SoftwareSerial.h>
   SoftwareSerial Bluetooth(10, 9); // RX, TX
  int LED = 13; // the on-board LED
  int Data; // the data received

     void setup() {
      Bluetooth.begin(9600);
     Serial.begin(9600);
     Serial.println("Waiting for command...");
      Bluetooth.println("Send 1 to turn on the LED. Send 0 to turn Off");
       pinMode(LED,OUTPUT);

     }

       void loop() {
        if (Bluetooth.available()){ //wait for data received
        Data=Bluetooth.read();
         if(Data=='1'){  
        digitalWrite(LED,1);
        Serial.println("LED On!");
    Bluetooth.println("LED On!");

1 个答案:

答案 0 :(得分:0)

需要多少时间,如果连接可用,如果连接不可用,则要花费多少时间。

无! available()read()立即返回。在读取或写入数据时,SoftwareSerial本身会给控制器带来一点负担。在发送9600时(每个字符花费1毫秒)时,如果发送缓冲区尚未满,则并行发生其他事情。 但是,SoftwareSerial无法全双工工作,因此在写入时无法读取任何内容。