//#include <SoftwareSerial.h> //引用库文件,这个文件应该是用于软件串口输出的
//SoftwareSerial BT(PB_3, PB_6); //定义蓝牙输入输出引脚
//PB_6为RX,接HC05的TX针脚
//PB_3为TX,接HC05的RX针脚
void setup() {
Serial.begin(9600); //初始化 Arduino 的硬串口
//BT.begin(9600); //初始化 Arduino 的硬串口
pinMode(PB_1, OUTPUT);
}
void loop() {
if (Serial.available() > 0) {
char receivedChar = Serial.read();
if (receivedChar == 'A') {
digitalWrite(PB_1, HIGH);
Serial.println("led on");
} else if (receivedChar == 'B') {
digitalWrite(PB_1, LOW);
Serial.println("led off");
}
Serial.print("Received Data: ");
Serial.println(receivedChar);
}
}
串口通信代码
最新推荐文章于 2025-01-20 10:31:50 发布