 #define BLE_RST   4
 
 // create peripheral instance, see pinouts above
-BLEPeripheral blePeripheral = BLEPeripheral(BLE_REQ, BLE_RDY, BLE_RST);
-BLEBondStore bleBondStore;
-
-const unsigned char hidReportReferenceDescriptorValue1[] = { 0x00, 0x01 };
-const unsigned char hidInformationCharacteriticValue[]   = { 0x11, 0x01, 0x00, 0x03 };
-
-// https://github.com/NordicSemiconductor/ble-sdk-arduino/blob/master/libraries/BLE/examples/ble_HID_keyboard_template/USD%20HID%20Report%20Descriptor%20-%20Keyboard.txt
-const unsigned char hidReportDescriptorValue[] = {
-  0x05, 0x01,                         // Usage Page (Generic Desktop)
-  0x09, 0x06,                         // Usage (Keyboard)
-  0xA1, 0x01,                         // Collection (Application)
-  0x05, 0x07,                         //     Usage Page (Key Codes)
-  0x19, 0xe0,                         //     Usage Minimum (224)
-  0x29, 0xe7,                         //     Usage Maximum (231)
-  0x15, 0x00,                         //     Logical Minimum (0)
-  0x25, 0x01,                         //     Logical Maximum (1)
-  0x75, 0x01,                         //     Report Size (1)
-  0x95, 0x08,                         //     Report Count (8)
-  0x81, 0x02,                         //     Input (Data, Variable, Absolute)
-
-  0x95, 0x01,                         //     Report Count (1)
-  0x75, 0x08,                         //     Report Size (8)
-  0x81, 0x01,                         //     Input (Constant) reserved byte(1)
-
-  0x95, 0x05,                         //     Report Count (5)
-  0x75, 0x01,                         //     Report Size (1)
-  0x05, 0x08,                         //     Usage Page (Page# for LEDs)
-  0x19, 0x01,                         //     Usage Minimum (1)
-  0x29, 0x05,                         //     Usage Maximum (5)
-  0x91, 0x02,                         //     Output (Data, Variable, Absolute), Led report
-  0x95, 0x01,                         //     Report Count (1)
-  0x75, 0x03,                         //     Report Size (3)
-  0x91, 0x01,                         //     Output (Data, Variable, Absolute), Led report padding
-
-  0x95, 0x06,                         //     Report Count (6)
-  0x75, 0x08,                         //     Report Size (8)
-  0x15, 0x00,                         //     Logical Minimum (0)
-  0x25, 0x65,                         //     Logical Maximum (101)
-  0x05, 0x07,                         //     Usage Page (Key codes)
-  0x19, 0x00,                         //     Usage Minimum (0)
-  0x29, 0x65,                         //     Usage Maximum (101)
-  0x81, 0x00,                         //     Input (Data, Array) Key array(6 bytes)
-
-
-  0x09, 0x05,                         //     Usage (Vendor Defined)
-  0x15, 0x00,                         //     Logical Minimum (0)
-  0x26, 0xFF, 0x00,                   //     Logical Maximum (255)
-  0x75, 0x08,                         //     Report Count (2)
-  0x95, 0x02,                         //     Report Size (8 bit)
-  0xB1, 0x02,                         //     Feature (Data, Variable, Absolute)
-
-  0xC0                                // End Collection (Application)
-};
-const unsigned char hidReportReferenceDescriptorValue2[] = {0x00, 0x02};
-
-
-BLEService                       hidService                              = BLEService("1812");
-BLECharacteristic                hidReportCharacteristic                 = BLECharacteristic("2A4D", BLERead | BLENotify, 8);
-BLEDescriptor                    reportReferenceDescriptor1              = BLEDescriptor("2908", hidReportReferenceDescriptorValue1, sizeof(hidReportReferenceDescriptorValue1));
-BLEConstantCharacteristic        hidInformationCharacteristic            = BLEConstantCharacteristic("2a4a", hidInformationCharacteriticValue, sizeof(hidInformationCharacteriticValue));
-BLEUnsignedCharCharacteristic    hidProtocolModeCharacteristic           = BLEUnsignedCharCharacteristic("2a4e", BLERead | BLEWriteWithoutResponse);
-BLEUnsignedCharCharacteristic    hidControlPointCharacteristic           = BLEUnsignedCharCharacteristic("2a4c",BLEWriteWithoutResponse);
-BLEConstantCharacteristic        hidReportDescriptor                     = BLEConstantCharacteristic("2a4b", hidReportDescriptorValue, sizeof(hidReportDescriptorValue));
-BLEUnsignedCharCharacteristic    hidReportOutputCharacteristic           = BLEUnsignedCharCharacteristic("2a4f", BLERead | BLEWrite | BLEWriteWithoutResponse);
-BLEDescriptor                    reportReferenceDescriptor2              = BLEDescriptor("2908", hidReportReferenceDescriptorValue2, sizeof(hidReportReferenceDescriptorValue2));
-BLECharacteristic                bootKeyboardInputReportCharacateristic  = BLECharacteristic("2A22", BLERead | BLENotify, 8);
-BLEUnsignedCharCharacteristic    bootKeyboardOutputReportCharacateristic = BLEUnsignedCharCharacteristic("2A23", BLERead | BLEWrite | BLEWriteWithoutResponse);
-
+BLEHIDPeripheral bleHIDPeripheral = BLEHIDPeripheral(BLE_REQ, BLE_RDY, BLE_RST);
+BLEKeyboard bleKeyboard;
 
 void setup() {
   Serial.begin(9600);
 #if defined (__AVR_ATmega32U4__)
-  delay(5000);  //5 seconds delay for enabling to see the start up comments on the serial board
+  while(!Serial);
 #endif
 
-  // clears bond data on every boot
-  bleBondStore.clearData();
+   // clear bond store data
+  bleHIDPeripheral.clearBondStoreData();
+  
+  bleHIDPeripheral.setLocalName("HID Keyboard");
+  bleHIDPeripheral.addHID(bleKeyboard);
 
-  blePeripheral.setBondStore(bleBondStore);
+  bleHIDPeripheral.begin();
 
-  blePeripheral.setDeviceName("Arduino Keyboard");
-  blePeripheral.setAppearance(961);
-
-  blePeripheral.setLocalName("HID-keyboard");
-  blePeripheral.setAdvertisedServiceUuid(hidService.uuid());
-
-  // add attributes (services, characteristics, descriptors) to peripheral
-  blePeripheral.addAttribute(hidService);
-  blePeripheral.addAttribute(hidReportCharacteristic);
-  blePeripheral.addAttribute(reportReferenceDescriptor1);
-  blePeripheral.addAttribute(hidInformationCharacteristic);
-  blePeripheral.addAttribute(hidProtocolModeCharacteristic);
-  blePeripheral.addAttribute(hidControlPointCharacteristic);
-  blePeripheral.addAttribute(hidReportDescriptor);
-  blePeripheral.addAttribute(hidReportOutputCharacteristic);
-  blePeripheral.addAttribute(reportReferenceDescriptor2);
-  blePeripheral.addAttribute(bootKeyboardInputReportCharacateristic);
-  blePeripheral.addAttribute(bootKeyboardOutputReportCharacateristic);
-
-  // initialize characteristics values
-  hidProtocolModeCharacteristic.setValue(0x01);
-
-  unsigned char bootKeyboardInputReportCharacateristicValue[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
-  bootKeyboardInputReportCharacateristic.setValue(bootKeyboardInputReportCharacateristicValue, sizeof(bootKeyboardInputReportCharacateristicValue));
-
-  // begin initialization
-  blePeripheral.begin();
-
-  Serial.println(F("BLE HID Keyboard Peripheral"));
+  Serial.println(F("BLE HID Keyboard"));
 }
 
 void loop() {
-  BLECentral central = blePeripheral.central();
+  BLECentral central = bleHIDPeripheral.central();
 
   if (central) {
     // central connected to peripheral

// Import libraries (BLEPeripheral depends on SPI)
#include <SPI.h>
#include <BLEPeripheral.h>

// define pins (varies per shield/board)
#define BLE_REQ   6

    Serial.println(central.address());

    while (central.connected()) {
      if (Serial.available() > 0) {
        // read in character
        char c = Serial.read();

        Serial.print(F("c = "));
        Serial.println(c);
        
        bleKeyboard.print(c);
      }
    }

