      and can be used by remote devices to identify this BLE device
      The name can be changed but maybe be truncated based on space left in advertisement packet */
   blePeripheral.setLocalName("CurieDice");
-  blePeripheral.setAdvertisedServiceUuid(batteryService.uuid());  // add the service UUID
-  blePeripheral.addAttribute(batteryService);   // Add the BLE Battery service
-  blePeripheral.addAttribute(batteryLevelChar); // add the battery level characteristic
+  blePeripheral.setAdvertisedServiceUuid(diceService.uuid());
+  blePeripheral.addAttribute(diceService);
+  blePeripheral.addAttribute(diceCommandCharacteristic);
+  blePeripheral.addAttribute(diceRollCharacteristic);
   blePeripheral.setEventHandler(BLEConnected, connectHandler);
   blePeripheral.setEventHandler(BLEDisconnected, disconnectHandler);
-  batteryLevelChar.setValue((unsigned char *)vraw,20);   // initial value for this characteristic
-
-  /* Now activate the BLE device.  It will start continuously transmitting BLE
-     advertising packets and will be visible to remote BLE central devices
-     until it receives a new connection */
+  diceCommandCharacteristic.setEventHandler(BLEWritten, commandHandler);
+    
+  //diceRollCharacteristic.setValue((unsigned char *)vraw,20);
+
+
   blePeripheral.begin();
   SERIAL_PRINTLN("Bluetooth device active, waiting for connections...");
 


  imuRead();
    
  if (gConnect) {
    SERIAL_PRINT("Sending: ");
    vraw[6] = (int16_t) movement;
    int16_t stillDur = (stillMillis>32000)? 32000 : stillMillis;
    vraw[7] = stillDur;
    vraw[8] = diceId;
    vraw[9] = nextSeqNum();
    batteryLevelChar.setValue((unsigned char*) vraw, 20);
  }

  if ((millis()-ledLapse) > 1000) {
    ledLapse = millis();
    ledState = !ledState;

    if (stillMillis==0) {
      stillBegin = millis();
      stillMillis = 1;
      rollSent = false;
    }
    else {
      stillMillis = millis() - stillBegin;
