// SD Card 1: Detect SD cards to the North, report their size

#include "SFBSDRaw.h"           // Explicitly access the SDRaw library

SDRaw mySD;                     // Allocate space for a raw sdcard controller

void setup() {
  mySD.begin(NORTH);            // Set up for 'IXM SD Cell' connectivity on East
}

void loop() { 
  u8 led = BODY_RGB_GREEN_PIN;  // Assume we have a card

  if (!mySD.isActive()) {       // If controller is inactive, try to..

    if (mySD.init())            // ..initialize it
      logNormal("Card found!  Block count = %d\n", mySD.getBlockCount());
    else
      led = BODY_RGB_RED_PIN;   // Or blink red if still no card yet

  } else {                      // If controller is active, just check card status

    if (mySD.readStatus() != 0) { // which should be zero.  If not, end the session.
      logNormal("Card lost.  Ending.\n");
      mySD.end();
    }

  } 
  ledOn(led);  delay(1000);     // Blink green or red
  ledOff(led); delay(1000);     
}
