//This example code is in the Public Domain (or CC0 licensed, at your option.)
//By Evandro Copercini - 2018
//
//This example creates a bridge between Serial and Classical Bluetooth (SPP)
//and also demonstrate that SerialBT have the same functionalities of a normal Serial
#include "BluetoothSerial.h"
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
BluetoothSerial SerialBT;
void setup() {
Serial.begin(115200);
SerialBT.begin("ESP32test"); //Bluetooth device name
Serial.println("The device started, now you can pair it with bluetooth!");
}
void loop() {
if (Serial.available()) {
SerialBT.write(Serial.read());//将串口收到的数据,再通过蓝牙串口转发出去
Serial.println("由SerialBT打印");
}
if (SerialBT.available()) {//将蓝牙串口收到的数据,再通过串口把信息发回给电脑
Serial.write(SerialBT.read());
Serial.println("由Serial打印");
}
delay(20);
}
ESP32+经典蓝牙
最新推荐文章于 2024-03-27 07:49:05 发布