 
 void disconnectHandler(BLECentral& central)
 {
+  gConnect = false;
   SERIAL_PRINT("Disconnected from central: ");
-  gConnect = false;
   digitalWrite(13, LOW);  
+}
+
+void commandHandler(BLECentral &central, BLECharacteristic &characteristic)
+{
+  int cmd = diceCommandCharacteristic.value();
 }
 
 void loop() {

     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.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 */
  blePeripheral.begin();
  SERIAL_PRINTLN("Bluetooth device active, waiting for connections...");


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