| 
  • 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
 

DanielAssumpcao_Lab5

Page history last edited by Vivien Tsao 7 years, 2 months ago

3. 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?

You can write 14 characters on one line, and 6 lines.

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

 

 

3.

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

#include <SPI.h>
#include <SD.h>
 
//On the Arduino Micro, the SS pin is defined in software as pin 17.
const int chipSelect = 17;
 
void setup()
{
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
  delay(1000); //this 1 second delay isn't strictly speaking necessary, but it seems to smooth over the USB serial monitor a bit.
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
 
  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(dataFile) {
     //Write it
     dataFile.print("He who must not be named");
   }
   dataFile.close();
   dataFile = SD.open("datalog.txt");
  // if the file is available, write to it:
  if (dataFile) {
    while (dataFile.available()) {
      Serial.write(dataFile.read());
    }
    dataFile.close();
  }  
  // if the file isn't open, pop up an error:
  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).

First copy all of the text from the first file into an array. Then create a new file and write the test string at the beginning of the file. Then copy the values of the array into the new file. Then save the new file over the old file.

4. a. Post your code.


#include <SPI.h>
#include <SD.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
 
//On the Arduino Micro, the SS pin is defined in software as pin 17.
const int chipSelect = 17;
 
void setup()
{
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
  delay(1000); //this 1 second delay isn't strictly speaking necessary, but it seems to smooth over the USB serial monitor a bit.
 
  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");
  Adafruit_PCD8544 display = Adafruit_PCD8544(7,6,5,-1,-1);
  display.begin();
  display.setContrast(60);
  display.clearDisplay();
  display.setCursor(0,0);
  // if the file is available, write to it:
  if (dataFile) {
    while (dataFile.available()) {
      char value = dataFile.read();
      display.print(value);
      Serial.write(value);
    }
    dataFile.close();
  }  
  // if the file isn't open, pop up an error:
  else {
    Serial.println("error opening datalog.txt");
  }
}
 
void loop()
{
}


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

Instead of writing to the arduino memory, I instead wrote to the SD card. I also had to store a space between each number to know when one number started and stopped. When reading it, I had to read until I encountered a space, which means that it is a full number. Then I need to combine the numbers together to form the full number.

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


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

 

Comments (0)

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