Jun ADI / Mbed 2 deprecated BLE_BatteryLevel_ADC_170608

Dependencies:   BLE_API mbed nRF51822 X_NUCLEO_IDB0XA1

Fork of BLE_BatteryLevel by Bluetooth Low Energy

Revision:
20:e7bc34a4a3db
Parent:
17:5afb0e5a48fc
Child:
21:d3784939bbc0
--- 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);
     }
+*/
 }