| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

lab5 batu

Page history last edited by Batuhan Altundas 10 years, 8 months ago

 

 

 

 

 

 

 

a. With the standard font, what is the longest message you can write across one line of the display? How many lines can you write?

14 characters message in 6 lines.

 

a. Include the code that you had to insert to do this in your lab writeup.

#include <SPI.h>

#include <SD.h>

 

const int chipSelect = 17;

 

void setup()

{

 // Open serial communications and wait for port to open:

  Serial.begin(9600);

  delay(1000);

  }

 

  Serial.print("Initializing SD card...");

  pinMode(17, OUTPUT); //set SS pin as output. 

 

  // see if the card is present and can be initialized:

  if (!SD.begin(chipSelect)) {

    Serial.println("Card failed, or not present");

    // don't do anything more:

    return;

  }

  Serial.println("card initialized.");

 

  // open the file. note that only one file can be open at a time,

  // so you have to close this one before opening another.

  File dataFile = SD.open("datalog.txt", FILE_WRITE);

 

  // if the file is available, write to it:

  if (dataFile) {

    dataFile.println("You shall not pass!");

    dataFile.close();

    Serial.println("The file has been modified");

  }  

  // if the file isn't open, pop up an error:

  else {

    Serial.println("error opening datalog.txt");

  } 

 dataFile = SD.open("datalog.txt");

 if (dataFile)

 {

   Serial.println("Modified File: ");

   while(dataFile.available())

   {

     Serial.write(dataFile.read());

   }

   dataFile.close();

 }

 else

   Serial.println("error opening datalog.txt");

}

void loop()

{

}

 

b. Explain what would you do differently (or show us your code!) to insert the same text string, but at the beginning of the file (without over-writing the current contents).

               use seek and position functions

 

 

 

 

Comments (0)

You don't have permission to comment on this page.