       }
       pinConfig[pin] = INPUT;
       
+      // force sending state immediately
+      //delay(10);
+      //checkDigitalInputs(true);  
     }
     break;
   case OUTPUT:

        digitalWrite(PIN_TO_DIGITAL(pin), LOW); // disable internal pull-ups
      }
      pinConfig[pin] = ANALOG;
      lastAnalogReads[pin] = -1;
    }
    break;
  case INPUT:

  //Serial.println(F("firmata reset"));
  BLE_Firmata.attach(SYSTEM_RESET, systemResetCallback);

  Serial.println(F("Begin firmata"));
  BLE_Firmata.begin();
  systemResetCallback();  // reset to default config 
}
/*==============================================================================
 * LOOP()
 *============================================================================*/

void loop() 
{
  // Check the BTLE link, how're we doing?
  BLEserial.pollACI();
  // Link status check
  BTLEstatus = BLEserial.getState();

  // Check if something has changed
  if (BTLEstatus != lastBTLEstatus) {
    // print it out!
    if (BTLEstatus == ACI_EVT_DEVICE_STARTED) {
        Serial.println(F("* Advertising started"));
    }
    if (BTLEstatus == ACI_EVT_CONNECTED) {
        Serial.println(F("* Connected!"));
        // initialize Firmata cleanly
         firmataInit();
    }
    if (BTLEstatus == ACI_EVT_DISCONNECTED) {
        Serial.println(F("* Disconnected or advertising timed out"));
    }
    // OK set the last status change to this one
    lastBTLEstatus = BTLEstatus;
  }
    
  // if not connected... bail
  if (BTLEstatus != ACI_EVT_CONNECTED) {
    delay(100);
    return;
  }
  
  // For debugging, see if there's data on the serial console, we would forwad it to BTLE
  if (Serial.available()) {
    BLEserial.write(Serial.read());
  }
  
  // Onto the Firmata main loop
  
  byte pin, analogPin;
  
  /* DIGITALREAD - as fast as possible, check for changes and output them to the
   * BTLE buffer using Serial.print()  */
  checkDigitalInputs();  

  /* SERIALREAD - processing incoming messagse as soon as possible, while still
