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

  • Stop wasting time looking for files and revisions. Connect your Gmail, DriveDropbox, and Slack accounts and in less than 2 minutes, Dokkio will automatically organize all your file attachments. Learn more and claim your free account.

View
 

Tosborvorn Art Lab 5

Page history last edited by xinyi xie 6 years, 3 months ago

Part A. Graphical LCD

 

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?

The font is 5x7 pixels, with 1 pixel space between each character, so you should be able to write 84 / 6 = 14 characters across.

How many lines one can write depends no the space between lines. The library defaults to 1 pixel, so each line is 8 pixels high, and we would be able to write 48 / 8 = 6 lines.

b. Upload a photo of your personal logo, shown on your LCD screen, to your Lab 5 page.

 


 

Part B. microSD Card

 

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

After initializing the SD card, the code would be the following (with edits in bold):

 

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

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

if (dataFile) {

  dataFile.print("He who must not be named!");

  // go back to the start of the file 

  dataFile.seek(0);

  while (dataFile.available()) {

    Serial.write(dataFile.read());

  }

  dataFile.close();

}

...

b. Explain what would you do differently to insert the same text string, but at the beginning of the file (without over-writing the current contents). You don't have to code this: just explain the process. If you're interested and have time make it work, show us your program.

Instead of just printing like in part (a), you would instead first read the content of the file (the first loop) and put it in a temporary character array. Then go back to the first position, write what you'd like to write, and write the temporary character array afterwards.

 

char tmp[dataFile.size() + 1];

memset(tmp, 0, sizeof(tmp));

int i = 0;

dataFile.seek(0);

while(dataFile.available()) {

  tmp[i] = dataFile.read();

  i ++;

}

 

dataFile.seek(0);

dataFile.print("Tom Marvolo Riddle! ");

dataFile.print(tmp);

c. Now tell us if your approach would work if the file were larger than your Arduino's memory (which is 2.5KB). If not, how could you work around that limitation?

While the previous approach is easy to implement, you'd need a temporary space the size of the file to store the data. So it wouldn't work for file larger than 2.5KB. To make this more efficient, you could create a temporary array the size of the text you'd like to add, and swap this with the original text, and continue doing this down the string. Suppose the original text is AABBCC, and the text you'd like to put in front is ZZ. The pseudocode is [something] like the following:

tmp = "ZZ"

for (i = 0; i < length(text); i += length(tmp)) {

  tmp2 = tmp

  tmp = text[i] through text[i + length(tmp)]

  text[i] through text[i + length(tmp)] = tmp2

}

 

d. Post your code.

e. Tell us what you had to change to make this work.

Aside from including relevant libraries and initializing SD card, I would have to do the following:

  • Check if there's already "code.txt" in the SD card. This is similar to checking if EEPROM is empty.
    • If the file does not exist, create an empty file, and go to setPassword() subroutine.
  • To set password, open the file in write mode, loop however many times the length of the code is. In each loop, read data from the encoder. Replace

     EEPROM.write(i + 1, cur);

          with

          codeFile.seek(0);
     codeFile.println(cur); 

          Of course, when everything is done, we need to close the file as well.

  • To read password, loop over, and do codeFile.read() until newline character is reached.

Part D. Create an Etch-a-Sketch!

 

a. Upload video of your Etch-a-Sketch in action!


 

b. Post a link to the Lab 5 Etch-a-Sketch Hall of Fame.

Done!

Comments (1)

xinyi xie said

at 9:28 pm on Aug 9, 2014

Great job!

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