stm32蓝牙模块用电脑连接单片机的串口通信的代码可以吗
时间: 2024-05-09 13:17:35 浏览: 212
可以,您可以参考以下代码:
```
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(10, 11); // RX | TX
void setup() {
Serial.begin(9600);
BTSerial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output
}
void loop() {
if (BTSerial.available()) { // Read from the HC-06 and print to the serial monitor
char c = BTSerial.read();
Serial.write(c);
}
if (Serial.available()) { // Read from the serial monitor and send to the HC-06
char c = Serial.read();
BTSerial.write(c);
if (c == '1') {
digitalWrite(LED_BUILTIN, HIGH); // Turn on the LED
} else if (c == '0') {
digitalWrite(LED_BUILTIN, LOW); // Turn off the LED
}
}
}
```
阅读全文