 /*
-  SD card read/write
- 
- This example shows how to read and write data to and from an SD card file 	
+Temperature Monitoring system
+
  The circuit:
  * SD card attached to SPI bus as follows:
  ** MOSI - pin 11
  ** MISO - pin 12
  ** CLK - pin 13
  ** CS - pin 4
- 
- created   Nov 2010
- by David A. Mellis
- modified 9 Apr 2012
- by Tom Igoe
- 
- This example code is in the public domain.
- 	 
+
+  filename has to be short :\ *NOTE*
+
  */
- 
-#include <SD.h>
+#include <SD.h> // Modified SD.cpp in SD library to allow for multiple SD.begin() calls
+// Add to Line 343 of SD.cpp: 'if (root.isOpen()) {root.close();}'
 
 File myFile;
 void readFileToSerial()
 {
   // re-open the file for reading:
-  myFile = SD.open("test.txt");
+  myFile = SD.open("mtest.txt");
   if (myFile) {
-    Serial.println("test.txt:");
+    Serial.println("mtest.txt:");
     
     // read from the file until there's nothing else in it:
     while (myFile.available()) {

{
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


    myFile.close();
  } else {
  	// if the file didn't open, print an error:
    Serial.println("error opening mtest.txt");
  }
}

int counter = 0;

// Append int value to file
void logToFile(char* filename, int value)
{
  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open(filename, FILE_WRITE);
  
  // if the file opened okay, write to it:
  if (myFile) {
    // Serial info
    Serial.print("Writing ");
    Serial.print(value);
    Serial.print(" to ");
    Serial.print(filename);
    Serial.print("... ");
    
    // Write value to file and close
    myFile.println(value);
    myFile.close();
    
    // Update counter
    counter++;
    
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening for writing.");
  }
}

