BourbonCreams

Untitled

Jul 26th, 2017
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.29 KB | None | 0 0
  1. #include <Bridge.h>
  2. #include <Console.h>
  3. #include <SPI.h>
  4. #include <SD.h>
  5.  
  6. File myFile;
  7.  
  8. void setup() {
  9.  
  10.   // Start using the Bridge.
  11.   Bridge.begin();
  12.  
  13.   // To output on the Serial Monitor
  14.   Console.begin();
  15.  
  16.   // Open serial communications and wait for port to open:
  17.   Serial.begin(9600);
  18.  
  19.   if (!SD.begin(4)) {
  20.     Console.println("initialization failed!");
  21.     //return;
  22.   }
  23.   Console.println("initialization done.");
  24.  
  25.   myFile = SD.open("test.txt", FILE_WRITE);
  26.  
  27. if (myFile){
  28.       Console.print("Writing to test.txt...\n");
  29.       myFile.println("testing 1, 2, 3.");
  30.       // close the file:
  31.       myFile.close();
  32.       Console.print("done.\n");
  33.   }
  34.   else{
  35.       // if the file didn't open, print an error:
  36.       Console.print("error opening test.txt\n");
  37.   }
  38.  
  39.   // re-open the file for reading:
  40.   myFile = SD.open("test.txt");
  41.   if (myFile){
  42.       Console.print("test.txt: ");
  43.  
  44.       // read from the file until there's nothing else in it:
  45.       while (myFile.available()) {
  46.         Console.print(myFile.read());
  47.       }
  48.       // close the file:
  49.       myFile.close();
  50.   }
  51.   else{
  52.       // if the file didn't open, print an error:
  53.       Console.print("error opening test.txt\n");
  54.   }
  55. }
  56.  
  57. void loop() {
  58.     Console.print("Loop\n");
  59.     delay(1000);
  60. }
Advertisement
Add Comment
Please, Sign In to add comment