daily pastebin goal
28%
SHARE
TWEET

sainsmart LCD 20x4 http://darylrobotproject.wordpress.com/

a guest Oct 12th, 2012 149 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Wire.h>
  2. #include <LCD.h>
  3. #include <LiquidCrystal_I2C.h>
  4.  
  5. #define I2C_ADDR    0x27  // Define I2C Address
  6. #define BACKLIGHT_PIN     3
  7. #define En_pin  2
  8. #define Rw_pin  1
  9. #define Rs_pin  0
  10. #define D4_pin  4
  11. #define D5_pin  5
  12. #define D6_pin  6
  13. #define D7_pin  7
  14.  
  15. LiquidCrystal_I2C       lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
  16.  
  17. void setup()
  18. {
  19.   lcd.begin (20,4,LCD_5x8DOTS);
  20.   lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE); // init the backlight
  21. }
  22.  
  23. void loop()
  24. {
  25.   demoDisplay();
  26.  
  27.   lcd.setBacklight(LOW);        // Backlight off
  28.   lcd.home ();                   // go home    
  29.   lcd.print("ABCDEFGHIJKLMNOPQRST");
  30.   lcd.setCursor ( 0, 1 );        // go to the next line
  31.   lcd.print("UVWXYZ 0123456789   ");
  32.   lcd.setCursor ( 0, 2 );        // go to the next line
  33.   lcd.print("abcdefghijklmnopqrst");
  34.   lcd.setCursor ( 0, 3 );        // go to the next line
  35.   lcd.print("uvwxyz <>!?@#$%&*() ");
  36.   lcd.setBacklight(HIGH);     // Backlight on
  37.   delay(3000);
  38.  
  39.   for (int i = 0; i < 20; i++) {
  40.     delay(300);
  41.     lcd.scrollDisplayLeft();
  42.   }
  43.   delay(3000);
  44.  
  45.   for (int i = 0; i < 20; i++) {
  46.     delay(300);
  47.     lcd.scrollDisplayRight();
  48.   }
  49.   delay(3000);
  50.  
  51.   lcd.clear(); // clear display, set cursor position to zero
  52.   lcd.autoscroll(); // This will 'right justify' text from the cursor
  53.   lcd.print("autoscroll");
  54.   delay(3000);
  55.  
  56.   lcd.clear(); // clear display, set cursor position to zero
  57.   lcd.noAutoscroll(); // This will 'left justify' text from the cursor
  58.   lcd.print("noAutoscroll");
  59.   delay(3000);
  60.  
  61.   lcd.clear(); // clear display, set cursor position to zero
  62.   // This is for text that flows Right to Left
  63.   lcd.rightToLeft();
  64.   lcd.print("rightToLeft");
  65.   delay(3000);
  66.  
  67.   lcd.clear(); // clear display, set cursor position to zero
  68.   lcd.leftToRight(); // This is for text that flows Left to Right
  69.   lcd.print("leftToRight");
  70.   delay(3000);
  71.  
  72.   lcd.clear(); // clear display, set cursor position to zero
  73.   lcd.print("blink");
  74.   lcd.blink(); // Turns on the blinking cursor
  75.   delay(3000);
  76.  
  77.   lcd.clear(); // clear display, set cursor position to zero
  78.   lcd.print("noBlink");                  
  79.   lcd.noBlink(); // Turns off the blinking cursor
  80.   delay(3000);
  81.  
  82.   lcd.clear(); // clear display, set cursor position to zero
  83.   lcd.print("cursor");
  84.   lcd.cursor(); // Turns the underline cursor on/off
  85.   delay(3000);
  86.  
  87.   lcd.clear(); // clear display, set cursor position to zero
  88.   lcd.print("noCursor");
  89.   lcd.noCursor(); // Turns the underline cursor on/off
  90.   delay(3000);
  91.  
  92. }
  93.  
  94. void demoDisplay()
  95. {
  96.   lcd.clear(); // clear display, set cursor position to zero
  97.   lcd.setBacklight(HIGH);     // Backlight on
  98.   lcd.setCursor (0,0);
  99.   lcd.print("Good afternoon,");
  100.   lcd.setCursor (0,1);        // go col 0 of line 1
  101.   lcd.print("gentlemen.");
  102.   delay(1000);
  103.   lcd.setCursor (0,2);        // go col 0 of line 2
  104.   lcd.print("I am a HAL 9000 ");
  105.   lcd.setCursor (0,3);        // go col 0 of line 3
  106.   lcd.print("computer.");
  107.   delay(4000);
  108.   wipeLines();
  109.  
  110.   lcd.setCursor (0,0);
  111.   lcd.print("I became operational");
  112.   lcd.setCursor (0,1);
  113.   lcd.print("at the H.A.L. plant ");
  114.   lcd.setCursor (0,2);
  115.   lcd.print("in Urbana, Illinois ");
  116.   lcd.setCursor (0,3);
  117.   lcd.print("on January 12 1992. ");
  118.   delay(4000);
  119.   wipeLines();
  120.  
  121.   lcd.setCursor (0,0);
  122.   lcd.print("If you'd like to    ");
  123.   lcd.setCursor (0,1);
  124.   lcd.print("hear it I can sing  ");
  125.   lcd.setCursor (0,2);
  126.   lcd.print("it for you.         ");
  127.   lcd.setCursor (0,3);
  128.   lcd.blink(); // Turns on the blinking cursor
  129.   delay(4000);
  130.   wipeLines();
  131.   lcd.noBlink(); // Turns off the blinking cursor
  132. }
  133.  
  134. void wipeLines() {
  135.   for (int y = 0; y < 4; y++) {
  136.     for (int x = 0; x < 20; x++) {
  137.       lcd.setCursor (x,y);
  138.       lcd.print(" ");
  139.       delay(5);
  140.     }
  141.   }
  142. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top