Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BLE_API HCSR04 X_NUCLEO_IDB0XA1 mbed
Fork of BLE_LED_Button_Nucleo by
Revision 14:c75f17f554c1, committed 2016-05-04
- Comitter:
- vseyok
- Date:
- Wed May 04 16:17:49 2016 +0000
- Parent:
- 13:0326e963b96c
- Commit message:
- it is not working(ultrasonic sensor)
Changed in this revision
--- a/ButtonService.h Tue May 03 10:20:03 2016 +0000
+++ b/ButtonService.h Wed May 04 16:17:49 2016 +0000
@@ -22,7 +22,7 @@
const static uint16_t BUTTON_SERVICE_UUID = 0xA010;
const static uint16_t BUTTON_STATE_CHARACTERISTIC_UUID = 0xA011;
- ButtonService(BLE &_ble, bool buttonPressedInitial) :
+ ButtonService(BLE &_ble, uint16_t buttonPressedInitial) :
ble(_ble), buttonState(BUTTON_STATE_CHARACTERISTIC_UUID, &buttonPressedInitial, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)
{
GattCharacteristic *charTable[] = {&buttonState};
@@ -30,13 +30,13 @@
ble.gattServer().addService(buttonService);
}
- void updateButtonState(bool newState) {
- ble.gattServer().write(buttonState.getValueHandle(), (uint8_t *)&newState, sizeof(bool));
+ void updateButtonState(uint16_t newState) {
+ ble.gattServer().write(buttonState.getValueHandle(), (uint8_t *)&newState, sizeof(uint16_t));
}
private:
BLE &ble;
- ReadOnlyGattCharacteristic<bool> buttonState;
+ ReadOnlyGattCharacteristic<uint16_t> buttonState;
};
#endif /* #ifndef __BLE_BUTTON_SERVICE_H__ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HCSR04.lib Wed May 04 16:17:49 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/prabhuvd/code/HCSR04/#71da0dbf4400
--- a/main.cpp Tue May 03 10:20:03 2016 +0000
+++ b/main.cpp Wed May 04 16:17:49 2016 +0000
@@ -18,15 +18,15 @@
#include "ble/BLE.h"
#include "LEDService.h"
#include "ButtonService.h"
-
+#include "hcsr04.h"
#define LED_ON 0
#define LED_OFF 1
DigitalOut alivenessLED(LED1, LED_OFF); // green
DigitalOut actuatedLED(LED2, LED_OFF); // red
InterruptIn button(PC_13);
-
-const static char DEVICE_NAME[] = "MY_BLE_DEVICE";
+HCSR04 usensor(D14,D15);
+const static char DEVICE_NAME[] = "vs_device";
static const uint16_t uuid16_list[] = {
LEDService::LED_SERVICE_UUID,
ButtonService::BUTTON_SERVICE_UUID
@@ -120,18 +120,18 @@
void button_down() {
if (!buttonServicePtr) return;
- buttonServicePtr->updateButtonState(true);
+ buttonServicePtr->updateButtonState(usensor.get_dist_cm());
}
void button_up() {
if (!buttonServicePtr) return;
- buttonServicePtr->updateButtonState(false);
+
}
int main(void)
{
// Blink the green LED!
ticker.attach(periodicCallback, 1);
-
+ usensor.start();
button.fall(&button_down);
button.rise(&button_up);
