Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. // created  28 Mar 2011
  2. // by Limor Fried
  3. // modified 9 Apr 2012
  4. // by Tom Igoe
  5. // modifed 23.3.2013
  6. // by Pavel Putna
  7.  
  8. #include <SD.h>
  9.  
  10. // nastaví proměné pro info karty
  11. Sd2Card card;
  12. SdVolume volume;
  13. SdFile root;
  14.  
  15. // nastavte správně
  16. // Arduino Ethernet shield: pin 4 - náš případ
  17. // Adafruit SD shields and modules: pin 10
  18. // Sparkfun SD shield: pin 8
  19. const int chipSelect = 4;    
  20.  
  21. void setup()
  22. {
  23.  Serial.begin(9600);
  24.    
  25.   Serial.print("\nInicializace SD karty...");
  26.   pinMode(4, OUTPUT);    
  27.  
  28.   // inicializace
  29.   if (!card.init(SPI_HALF_SPEED, chipSelect)) {
  30.     Serial.println("\nPametova karta nebyla detekovana");
  31.     return;
  32.   } else {
  33.    Serial.println("\nPametova karta nalezena.");
  34.   }
  35.  
  36.   // Určí typ karty
  37.   Serial.print("\nTyp karty: ");
  38.   switch(card.type()) {
  39.     case SD_CARD_TYPE_SD1:
  40.       Serial.println("SD1");
  41.       break;
  42.     case SD_CARD_TYPE_SD2:
  43.       Serial.println("SD2");
  44.       break;
  45.     case SD_CARD_TYPE_SDHC:
  46.       Serial.println("SDHC");
  47.       break;
  48.     default:
  49.       Serial.println("Neznama");
  50.   }
  51.  
  52.   // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
  53.   if (!volume.init(card)) {
  54.     Serial.println("System souboru FAT16/FAT32 nenalezen.\nZkuste naformatovat kartu");
  55.     return;
  56.   }
  57.  
  58.   // print the type and size of the first FAT-type volume
  59.   uint32_t volumesize;
  60.   Serial.print("\nVolume type is FAT");
  61.   Serial.println(volume.fatType(), DEC);
  62.   Serial.println();
  63.  
  64.   volumesize = volume.blocksPerCluster();    // clusters are collections of blocks
  65.   volumesize *= volume.clusterCount();       // we'll have a lot of clusters
  66.   volumesize *= 512;                            // SD card blocks are always 512 bytes
  67.   Serial.print("Volume size (bytes): ");
  68.   Serial.println(volumesize);
  69.   Serial.print("Volume size (Kbytes): ");
  70.   volumesize /= 1024;
  71.   Serial.println(volumesize);
  72.   Serial.print("Volume size (Mbytes): ");
  73.   volumesize /= 1024;
  74.   Serial.println(volumesize);
  75.  
  76.  
  77.   Serial.println("\nNalezene soubory na karte (nazev, datum a velikost v bajtech): ");
  78.   root.openRoot(volume);
  79.  
  80.   // list all files in the card with date and size
  81.   root.ls(LS_R | LS_DATE | LS_SIZE);
  82. }
  83.  
  84. void loop(void) {
  85. }