测试蓝牙模块
This commit is contained in:
parent
792ec0bcb3
commit
86e240d375
|
@ -0,0 +1,2 @@
|
|||
void bt_init();
|
||||
void bt_loop();
|
|
@ -12,5 +12,7 @@
|
|||
platform = espressif32
|
||||
board = esp32doit-devkit-v1
|
||||
framework = arduino
|
||||
lib_deps = madhephaestus/ESP32Servo@^0.12.0
|
||||
lib_deps =
|
||||
madhephaestus/ESP32Servo@^0.12.0
|
||||
h2zero/NimBLE-Arduino@^1.4.1
|
||||
monitor_speed = 115200
|
|
@ -0,0 +1,28 @@
|
|||
#include <NimBLEDevice.h>
|
||||
|
||||
#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
|
||||
#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"
|
||||
|
||||
void bt_init() {
|
||||
Serial.println("BLE START");
|
||||
|
||||
BLEDevice::init("BOT");
|
||||
BLEServer* pServer = BLEDevice::createServer();
|
||||
BLEService* pService = pServer->createService(SERVICE_UUID);
|
||||
BLECharacteristic* pCharacteristic = pService->createCharacteristic(
|
||||
CHARACTERISTIC_UUID, NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::WRITE);
|
||||
|
||||
pCharacteristic->setValue("Hello World says Neil");
|
||||
pService->start();
|
||||
BLEAdvertising* pAdvertising = BLEDevice::getAdvertising();
|
||||
pAdvertising->addServiceUUID(SERVICE_UUID);
|
||||
pAdvertising->setScanResponse(true);
|
||||
pAdvertising->setMinPreferred(0x06);
|
||||
pAdvertising->setMaxPreferred(0x12);
|
||||
|
||||
BLEDevice::startAdvertising();
|
||||
|
||||
Serial.println("Characteristic defined! Now you can read it in your phone!");
|
||||
}
|
||||
|
||||
void bt_loop() {}
|
|
@ -1,12 +1,15 @@
|
|||
#include <Arduino.h>
|
||||
#include <servo.h>
|
||||
#include <bt.h>
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
servo_init();
|
||||
bt_init();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
servo_loop();
|
||||
delay(1000);
|
||||
bt_loop();
|
||||
delay(100);
|
||||
}
|
|
@ -41,5 +41,4 @@ void servo_loop() {
|
|||
servo[i].detach();
|
||||
}
|
||||
pwm.detachPin(27);
|
||||
delay(500);
|
||||
}
|
Loading…
Reference in New Issue