waterlubber

project function lcd writer

Mar 19th, 2017
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.73 KB | None | 0 0
  1. //This is a function that prints the information for chapter, event and line. Line is a value that indicates which line of the information is being scrolled through, and
  2.  
  3. void printInfo(byte c, byte e, byte l) { //Take info of chapter, event, and line
  4.   Serial.print(F("Function Called: ")); //debugging, terrible, oh well it'll be gone soon
  5.   Serial.print(c);
  6.   Serial.print(F(""));
  7.   Serial.print(e);
  8.   Serial.print(F(" "));
  9.   Serial.println(l);
  10.   String fileString; //create a string to hold the file name to read from the SD card
  11.   char fileName[10] = {0};
  12.   char sdChar; //create a character to store for later use (you'll see it)
  13.   fileString = String(String(c) + String(e) + String(l) + ".txt"); //create a file name String
  14.   Serial.println(fileString); //debugging
  15.   fileString.toCharArray(fileName, 10); //convert it into a format that the SD library can work with
  16.   Serial.println(fileName);
  17.   sdData = SD.open(fileName); //open the file
  18.   if(!sdData) { //check if file exists
  19.     Serial.print(F("Error! File "));
  20.     Serial.print(fileName);
  21.     Serial.println(F(" not found!"));
  22.    
  23.   }
  24.   lcd.clear(); //clear the LCD as we are writing a new page
  25.   lcd.setCursor(0,0); //reset cursor
  26.   delay(10); //little bit of delay to allow anything to catch up
  27.   for(int x; x < 16; x++) { // this is a 16x2 lcd so make sure we stay within the bounds - files contain one line of text, 16 characters
  28.     while(sdData.available()){ //wait for SD to become available if it isn't already
  29.       sdChar = sdData.read(); //
  30.       Serial.print(sdChar);
  31.       lcd.setCursor(x, 0); //set the cursor to the right spot
  32.       lcd.print(sdChar); //print the character to the lcd
  33.       delay(5); //for cool effect
  34.     }
  35.     }
  36.   sdData.close(); //close the file
  37.   l = l + 1; //Increase the line by one and get ready to print the next thing - it reads the next file over and prints it on the next line
  38.   fileString = String(String(c) + String(e) + String(l) + ".txt"); //create a file name String
  39.   fileString.toCharArray(fileName, 10); //convert it into a format that the SD library can work with
  40.   Serial.println();
  41.   Serial.println(fileString);
  42.   Serial.println(fileName);
  43.  
  44.   //now do that stuff before, all over again!
  45.   sdData = SD.open(fileName); //open the file
  46.   if(!sdData) { //check if file exists
  47.     Serial.print(F("Error! File "));
  48.     Serial.print(fileName);
  49.     Serial.println(F(" not found!"));
  50.   }
  51.   lcd.clear(); //clear the LCD as we are writing a new page
  52.   lcd.setCursor(0,1);
  53.   delay(10);
  54.   for(int x; x < 16; x++) {
  55.     while(sdData.available()){
  56.       sdChar = sdData.read();
  57.       lcd.setCursor(x, 1); //set the cursor to the right spot
  58.       lcd.print(sdChar);
  59.       delay(5); //for cool effect
  60.     }
  61.   }
  62.   sdData.close();
  63. }
Advertisement
Add Comment
Please, Sign In to add comment