iOSのBLEコントローラアプリ「RCBController」とmbed HRM1017を接続し、RCサーボモータを操作するテストプログラムです。
Dependencies: BLE_API Servo mbed nRF51822
Fork of BLE_RCBController2 by
• ライブラリ類はUpdateしないでください。コンパイルエラーになります。
うまく接続できない時は、iPhone/iPadのBluetoothをOFF->ONしてキャッシュをクリアしてみてください。
Diff: main.cpp
- Revision:
- 5:d6d898857b2a
- Parent:
- 2:dd85fdc18224
--- a/main.cpp Wed Aug 20 13:41:01 2014 +0000 +++ b/main.cpp Fri Sep 19 04:04:05 2014 +0000 @@ -1,8 +1,9 @@ #include "mbed.h" #include "BLEDevice.h" #include "RCBController.h" +#include "Servo.h" -#define DBG 1 +#define DBG 0 BLEDevice ble; Serial pc(USBTX, USBRX); @@ -10,6 +11,7 @@ DigitalOut ConnectStateLed(LED1); PwmOut ControllerStateLed(LED2); +Servo servo1(P0_28), servo2(P0_29); /* RCBController Service */ static const uint16_t RCBController_service_uuid = 0xFFF0; @@ -24,7 +26,7 @@ RCBController controller; -void onConnected(uint16_t h) +void onConnected(Gap::Handle_t handle, const Gap::ConnectionParams_t *params) { ConnectStateLed = 0; #if DBG @@ -32,7 +34,7 @@ #endif } -void onDisconnected(uint16_t h) +void onDisconnected(Gap::Handle_t handle, Gap::DisconnectionReason_t reason) { ble.startAdvertising(); ConnectStateLed = 1; @@ -43,11 +45,11 @@ // GattEvent -void onDataWritten(uint16_t charHandle) +void onDataWritten(uint16_t charHandle, const GattCharacteristicWriteCBParams *params) { - if (charHandle == ControllerChar.getHandle()) { + if (charHandle == ControllerChar.getValueAttribute().getHandle()) { uint16_t bytesRead; - ble.readCharacteristicValue(ControllerChar.getHandle(),RCBControllerPayload, &bytesRead); + ble.readCharacteristicValue(ControllerChar.getValueAttribute().getHandle(),RCBControllerPayload, &bytesRead); memcpy( &controller.data[0], RCBControllerPayload, sizeof(controller)); #if DBG @@ -55,6 +57,8 @@ controller.data[5],controller.data[6],controller.data[7],controller.data[8],controller.data[9]); #endif ControllerStateLed = (float)controller.status.LeftAnalogLR / 255.0; + servo1 = (float)controller.status.LeftAnalogUD / 255.0; + servo2 = (float)controller.status.LeftAnalogLR / 255.0; } } @@ -69,6 +73,11 @@ #if DBG pc.printf("Start\n\r"); #endif + ConnectStateLed = 1; + servo1.calibrate(0.001,180.0); + servo2.calibrate(0.001,180.0); + servo1 = 0.5; + servo2 = 0.5; ble.init(); ble.onConnection(onConnected);