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

Page history last edited by Kevin Hsu 10 years, 11 months ago

PART A

3A. The smallest font is size 1 of the function display.setTextSize. A larger number results in larger font. With size one, I could write 14 characters across and 4 lines down.

<See Lab5_pic for picture.> 

 

PART B

3A. I added this to the loop named if(dataFile), after the contents have been read. 

    String dataString = ". Wingardium leviosa.";

    dataFile.println(dataString);

    Serial.println(dataString);

3B. I would add the same 3 line of code to the loop named if(dataFile), but place it before the while loop that reads the file.

4A. #include <Adafruit_GFX.h>

#include <Adafruit_PCD8544.h>

#include <SPI.h>

#include <SD.h>

Adafruit_PCD8544 display = Adafruit_PCD8544(7,6,5,-1,-1);

const int chipSelect = 17; 

void setup()

{

  display.begin();

  display.setContrast(50);

  display.setTextSize(0);

  display.setCursor(0, 0); //set top-left corner at text at positon 0,0 (upper left most section of screen). 

  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."); 

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

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

  if (dataFile) {

    while (dataFile.available()) {

      char readText = dataFile.read();

      Serial.write(readText);

      display.print(readText); 

    } 

    String dataString = ". Wingardium leviosa.";

    dataFile.println(dataString);

    Serial.println(dataString);

    display.print(dataString);

    display.display(); 

    dataFile.close();

  }  

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

  else {

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

  } 

} 

void loop()

{

}

 

5A. To write the music notes that my data logger collects, I would insert the line display.println(note) right before I store the note to the EEPROM, so that it also shows on the display.

 

PART D

Link to video: https://www.youtube.com/watch?v=fv3YqMDDh0A

Comments (0)

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