Modified sample program of BLE_BatteryLevel. The program add analog input pin setting and batteryLevel data is changed by analog input.
Dependencies: BLE_API mbed nRF51822 X_NUCLEO_IDB0XA1
Fork of BLE_BatteryLevel by
Revision 20:e7bc34a4a3db, committed 2017-06-08
- Comitter:
- Jun_adi
- Date:
- Thu Jun 08 05:22:45 2017 +0000
- Parent:
- 19:1e34f137b7ce
- Child:
- 21:d3784939bbc0
- Commit message:
- Change the analog input setting. It can change Battery level value by Analog input voltage.;
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Sep 20 12:27:09 2016 +0100
+++ b/main.cpp Thu Jun 08 05:22:45 2017 +0000
@@ -21,7 +21,12 @@
DigitalOut led1(LED1, 1);
Ticker t;
BatteryService *batteryService = NULL;
-uint8_t batteryLevel = 50;
+
+//uint8_t batteryLevel = 50;
+uint8_t batteryLevel = 50; // Change initial calue of batteryLevel
+
+//Pin setting for Analog input
+AnalogIn analogin(P0_4);
void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *disconnectionParams)
{
@@ -71,7 +76,12 @@
while (true) {
ble.waitForEvent(); // this will return upon any system event (such as an interrupt or a ticker wakeup)
-
+
+ //Read Anlog input voltage
+ batteryLevel = analogin.read()*100;
+ batteryService->updateBatteryLevel(batteryLevel);
+ }
+/*
// the magic battery processing
batteryLevel++;
if (batteryLevel > 100) {
@@ -80,4 +90,5 @@
batteryService->updateBatteryLevel(batteryLevel);
}
+*/
}
