arduino - 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!");
解决方案
需要多少时间,如果连接可用,以及在连接不可用的情况下花费了多少时间。
没有任何! available()
并read()
立即返回。在读取或写入数据时,SoftwareSerial 本身会给控制器带来一点负担。在以 9600 发送(每个字符需要 1 毫秒)时,如果发送缓冲区尚未满,其他事情可能会并行发生。但是 SoftwareSerial 不能全双工工作,所以在写入时,什么都不能读取。
推荐阅读
- if-statement - How to get a total number of occurrences in an IF statement
- powershell - Trailing spaces during integer to string conversion in power shell script
- kubernetes - Hybrid between replicaset and daemonset
- javascript - Is it possible to change domparser element to string?
- three.js - Update texture with three.js
- javascript - 页面刷新时 Vue SPA 中的 Auth0 客户端为空
- sql - 使用 SQL 访问数组中 JSON 对象中的键、值
- python - 在 windows 10 中安装虚拟环境
- python-3.x - 如何在不同的数据帧上生成交叉验证以进行监督分类?
- yaml - 在其他 `substitutions` 中包含默认替换