测试蓝牙模块
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
|
platform = espressif32
|
||||||
board = esp32doit-devkit-v1
|
board = esp32doit-devkit-v1
|
||||||
framework = arduino
|
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
|
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 <Arduino.h>
|
||||||
#include <servo.h>
|
#include <servo.h>
|
||||||
|
#include <bt.h>
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
servo_init();
|
servo_init();
|
||||||
|
bt_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
servo_loop();
|
servo_loop();
|
||||||
delay(1000);
|
bt_loop();
|
||||||
|
delay(100);
|
||||||
}
|
}
|
|
@ -41,5 +41,4 @@ void servo_loop() {
|
||||||
servo[i].detach();
|
servo[i].detach();
|
||||||
}
|
}
|
||||||
pwm.detachPin(27);
|
pwm.detachPin(27);
|
||||||
delay(500);
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue