How to turn a WaveShare nRF51-BLE400 into a discoverable beacon using mbed

Dependencies:   mbed BLE_API nRF51822

Port for WaveShare BLE400 (chip nRF51 Aliexpress devboard)
Android Evothings good example for Nordic nRF51822-DK

As target for mbed-online used <Nordic nRF51822>
- (Large green board Nordic nRF51822-mKIT, actually deprecated on 01/03/2019)

Briefly: Handle via Evothings BLE Application 4 LEDs and 2 Buttons(via notify messages).

Figure 1: Evothings Android application screenshot

Evothings application screenshot

Android Evothings application sources

Android application APK

Happy coding!
maxxir 02/03/19

Revision:
18:0cbeb28ce4f6
Parent:
17:9071edee0b13
--- a/main.cpp	Fri Mar 01 19:51:06 2019 +0000
+++ b/main.cpp	Sun Mar 03 15:14:13 2019 +0000
@@ -89,11 +89,11 @@
 //-------------------------------------------------------------------------
 
 // define our digital in values we will be using for the characteristic
-//WaveShare BLE400 edited
-DigitalIn button1(P0_16);
-DigitalIn button2(P0_17);
-//DigitalIn button3(P0_14); //Just substitute for check, actually not present on WaveShare BLE400
-//DigitalIn button4(P0_15); //Just substitute for check, actually not present on WaveShare BLE400
+//WaveShare BLE400 digital inputs as Button inputs
+DigitalIn button1(P0_16); //KEY1
+DigitalIn button2(P0_17); //KEY2
+//DigitalIn button3(P0_14); //Should not used for WaveShare BLE400
+//DigitalIn button4(P0_15); //Should not used for WaveShare BLE400
 
 uint8_t button_new_value = 0;
 uint8_t button_old_value = button_new_value;
@@ -124,30 +124,15 @@
 //-------------------------------------------------------------------------
 // LED handling
 //-------------------------------------------------------------------------
-//WaveShare BLE400 edited
+//WaveShare BLE400 digital outputs as LED outputs
 DigitalOut led1(P0_18);
 DigitalOut led2(P0_19);
 DigitalOut led3(P0_20);
 DigitalOut led4(P0_21);
-DigitalOut led5(P0_22); //Actually not used here
+DigitalOut led5(P0_22); //Used here to view BLE connect/disconnect
 
 uint8_t led_value = 0;
 
-/*
-void onLedDataWritten(const uint8_t* value, uint8_t length) 
-{
-    // we only care about a single byte
-    led_value = value[0];
-
-    // depending on the value coming through; set/unset LED's
-    if ((led_value & 0x01) != 0) led1.write(0); else led1.write(1);
-    if ((led_value & 0x02) != 0) led2.write(0); else led2.write(1);
-    if ((led_value & 0x04) != 0) led3.write(0); else led3.write(1);
-    if ((led_value & 0x08) != 0) led4.write(0); else led4.write(1);
-
-    INFO_NL("     led state: [0x%02x]", led_value);
-}
-*/
 //Adapted for WaveShare BLE400, LED_ON = HIGH (NRF51822-DK vice versa LED_ON = LOW)
 void onLedDataWritten(const uint8_t* value, uint8_t length) 
 {
@@ -191,7 +176,7 @@
     INFO_NL(">> disconnected");
     ble.gap().startAdvertising(); // restart advertising
     INFO_NL(">> device advertising");
-    //LED5=OFF on connection (for BLE400)
+    //LED5=OFF on diconnection (for BLE400)
     led5.write(0);
 }