awinograd

Lab 5 - SD -> LCD

May 4th, 2012
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.60 KB | None | 0 0
  1. /*
  2.   Graphics
  3.  
  4.  Runs a text-only demo on the Nokia 5110 LCD.
  5.  
  6.  The circuit:
  7.  * Nokia 5110 Connected as follows:
  8. LED   --> 50 Ohm   -->   3.3V
  9. SCLK        -->          Pin 1 (SCLK)
  10. DN(MOSI)    -->          Pin 2 (MOSI)
  11. D/C         -->          Pin 4
  12. RST         -->          Pin 8
  13. SCE         -->          Pin 9
  14. GND         -->          GND
  15. Vcc         -->          Pin 10
  16.  
  17.  By Andrew Lindsay (Adapted by Megan Wachs and edited by Matthew Seal and Akil Srinivasan)
  18.  */
  19.  /*IF we are not using the Graphics or Bitmap capabilities
  20.  of the LCD, save code space with these #defines*/
  21.  
  22. #include <SD.h>
  23. const int chipSelect = 12;
  24.  
  25. #include <nokia_5110_lcd.h>
  26.  
  27. //LCD PINS
  28. #define LCD_PWR   10
  29. #define LCD_SCE   9
  30. #define LCD_RESET 8
  31. #define LCD_DC    4
  32.  
  33. Nokia_5110_lcd lcd(LCD_PWR, LCD_DC, LCD_SCE, LCD_RESET);
  34.  
  35. void initSD(){
  36.   Serial.begin(9600);
  37.   Serial.print("Initializing SD card...");
  38.   // see if the card is present and can be initialized:
  39.   if (!SD.begin(chipSelect)) {
  40.     Serial.println("Card failed, or not present");
  41.     // don't do anything more:
  42.     return;
  43.   }
  44.   Serial.println("card initialized.");  
  45. }
  46.  
  47. void setup()
  48. {  
  49.   initSD();
  50.   File dataFile = SD.open("datalog.txt");
  51.   lcd.init(80); //parameter is contrast value, between 0 [low] and 127 [high]
  52.   lcd.clear();
  53.  
  54.   if (dataFile) {
  55.     while (dataFile.available()) {
  56.       lcd.writeChar(dataFile.read(), MODE_NORMAL);
  57.       delay(250);
  58.     }
  59.     dataFile.close();
  60.   }  
  61.   // if the file isn't open, pop up an error:
  62.   else {
  63.     Serial.println("error opening datalog.txt");
  64.   }
  65. }
  66.  
  67. /* loop */
  68. void loop() {
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment