Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Bridge.h>
- #include <Console.h>
- #include <SPI.h>
- #include <SD.h>
- File myFile;
- void setup() {
- // Start using the Bridge.
- Bridge.begin();
- // To output on the Serial Monitor
- Console.begin();
- // Open serial communications and wait for port to open:
- Serial.begin(9600);
- if (!SD.begin(4)) {
- Console.println("initialization failed!");
- //return;
- }
- Console.println("initialization done.");
- myFile = SD.open("test.txt", FILE_WRITE);
- if (myFile){
- Console.print("Writing to test.txt...\n");
- myFile.println("testing 1, 2, 3.");
- // close the file:
- myFile.close();
- Console.print("done.\n");
- }
- else{
- // if the file didn't open, print an error:
- Console.print("error opening test.txt\n");
- }
- // re-open the file for reading:
- myFile = SD.open("test.txt");
- if (myFile){
- Console.print("test.txt: ");
- // read from the file until there's nothing else in it:
- while (myFile.available()) {
- Console.print(myFile.read());
- }
- // close the file:
- myFile.close();
- }
- else{
- // if the file didn't open, print an error:
- Console.print("error opening test.txt\n");
- }
- }
- void loop() {
- Console.print("Loop\n");
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment