首页 > 解决方案 > HC 05 带 arduino uno 的蓝牙模块

问题描述

我想知道执行“Bluetooth.available();” 需要多少时间,如果连接可用,以及在连接不可用的情况下花费了多少时间。

也为

蓝牙.read() ; Bluetooth.println("LED 亮!");

需要多少时间。

我的项目对时间很敏感,所以问。好心的帮助

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

     #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!");

标签: arduinoarduino-unohc-05

解决方案


需要多少时间,如果连接可用,以及在连接不可用的情况下花费了多少时间。

没有任何! available()read()立即返回。在读取或写入数据时,SoftwareSerial 本身会给控制器带来一点负担。在以 9600 发送(每个字符需要 1 毫秒)时,如果发送缓冲区尚未满,其他事情可能会并行发生。但是 SoftwareSerial 不能全双工工作,所以在写入时,什么都不能读取。


推荐阅读