示例#1
0
void setup() {
  
    // set up Serial library at 9600 bps
  Serial.begin(9600);           
  
  if (!card.init()) {
    error("Card init. failed!");
  }
  if (!vol.init(card)) {
    error("No partition!");
  }
  if (!root.openRoot(vol)) {
    error("Couldn't open dir");
  }

  PgmPrintln("Files found:");
  root.ls();
  
  // declare the Pins
  pinMode(readyLEDPin, OUTPUT); 
 // pinMode(blowLEDPin, OUTPUT); 
 // pinMode(waitLEDPin, OUTPUT); 
  pinMode(level0LEDPin, OUTPUT); 
  pinMode(level1LEDPin, OUTPUT); 
  pinMode(level2LEDPin, OUTPUT); 
  pinMode(level3LEDPin, OUTPUT); 
  pinMode(buttonPin, INPUT); 
  
  initialButtonState = digitalRead(buttonPin);
  Serial.println("initial switch value= " + initialButtonState);
  
  ///***** set the char mode based on the pot position
  initialPot = analogRead(PotPin);  
  Serial.println("initial pot value= " + initialPot);
   
  range = map(initialPot, 0, 1024, 0, 3);
  Serial.println("initial pot range is: " + range);
  switch (range) {
  case 0:    // your hand is on the sensor
    mode = 0;
    Serial.println("initial mode set to 0: princess");
    break;
  case 1:    // your hand is close to the sensor
    mode = 1;
    Serial.println("initial mode set to 1: pirate");
    break;
  case 2:    // your hand is a few inches from the sensor
    mode = 2;
    Serial.println("initial mode set to 2: halloween");
    break;
  case 3:    // your hand is nowhere near the sensor
    mode = 3;
    Serial.println("initial mode set to 3: insult");
    break;
  }   
}
示例#2
0
//////////////////////////////////// SETUP
void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps for debugging
  
  putstring_nl("\nWave test!");  // say we woke up!
  
  putstring("Free RAM: ");       // This can help with debugging, running out of RAM is bad
  Serial.println(FreeRam());

  //  if (!card.init(true)) { //play with 4 MHz spi if 8MHz isn't working for you
  if (!card.init()) {         //play with 8 MHz spi (default faster!)  
    error("Card init. failed!");  // Something went wrong, lets print out why
  }
  
  // enable optimize read - some cards may timeout. Disable if you're having problems
  card.partialBlockRead(true);
  
  // Now we will look for a FAT partition!
  uint8_t part;
  for (part = 0; part < 5; part++) {   // we have up to 5 slots to look in
    if (vol.init(card, part)) 
      break;                           // we found one, lets bail
  }
  if (part == 5) {                     // if we ended up not finding one  :(
    error("No valid FAT partition!");  // Something went wrong, lets print out why
  }
  
  // Lets tell the user about what we found
  putstring("Using partition ");
  Serial.print(part, DEC);
  putstring(", type is FAT");
  Serial.println(vol.fatType(), DEC);     // FAT16 or FAT32?
  
  // Try to open the root directory
  if (!root.openRoot(vol)) {
    error("Can't open root dir!");      // Something went wrong,
  }
  
  // Whew! We got past the tough parts.
  putstring_nl("Files found (* = fragmented):");

  // Print out all of the files in all the directories.
  root.ls(LS_R | LS_FLAG_FRAGMENTED);
}