Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include <LCD.h>
- #include <LiquidCrystal_I2C.h>
- #define I2C_ADDR 0x27 // Define I2C Address
- #define BACKLIGHT_PIN 3
- #define En_pin 2
- #define Rw_pin 1
- #define Rs_pin 0
- #define D4_pin 4
- #define D5_pin 5
- #define D6_pin 6
- #define D7_pin 7
- LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
- void setup()
- {
- lcd.begin (20,4,LCD_5x8DOTS);
- lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE); // init the backlight
- }
- void loop()
- {
- demoDisplay();
- lcd.setBacklight(LOW); // Backlight off
- lcd.home (); // go home
- lcd.print("ABCDEFGHIJKLMNOPQRST");
- lcd.setCursor ( 0, 1 ); // go to the next line
- lcd.print("UVWXYZ 0123456789 ");
- lcd.setCursor ( 0, 2 ); // go to the next line
- lcd.print("abcdefghijklmnopqrst");
- lcd.setCursor ( 0, 3 ); // go to the next line
- lcd.print("uvwxyz <>!?@#$%&*() ");
- lcd.setBacklight(HIGH); // Backlight on
- delay(3000);
- for (int i = 0; i < 20; i++) {
- delay(300);
- lcd.scrollDisplayLeft();
- }
- delay(3000);
- for (int i = 0; i < 20; i++) {
- delay(300);
- lcd.scrollDisplayRight();
- }
- delay(3000);
- lcd.clear(); // clear display, set cursor position to zero
- lcd.autoscroll(); // This will 'right justify' text from the cursor
- lcd.print("autoscroll");
- delay(3000);
- lcd.clear(); // clear display, set cursor position to zero
- lcd.noAutoscroll(); // This will 'left justify' text from the cursor
- lcd.print("noAutoscroll");
- delay(3000);
- lcd.clear(); // clear display, set cursor position to zero
- // This is for text that flows Right to Left
- lcd.rightToLeft();
- lcd.print("rightToLeft");
- delay(3000);
- lcd.clear(); // clear display, set cursor position to zero
- lcd.leftToRight(); // This is for text that flows Left to Right
- lcd.print("leftToRight");
- delay(3000);
- lcd.clear(); // clear display, set cursor position to zero
- lcd.print("blink");
- lcd.blink(); // Turns on the blinking cursor
- delay(3000);
- lcd.clear(); // clear display, set cursor position to zero
- lcd.print("noBlink");
- lcd.noBlink(); // Turns off the blinking cursor
- delay(3000);
- lcd.clear(); // clear display, set cursor position to zero
- lcd.print("cursor");
- lcd.cursor(); // Turns the underline cursor on/off
- delay(3000);
- lcd.clear(); // clear display, set cursor position to zero
- lcd.print("noCursor");
- lcd.noCursor(); // Turns the underline cursor on/off
- delay(3000);
- }
- void demoDisplay()
- {
- lcd.clear(); // clear display, set cursor position to zero
- lcd.setBacklight(HIGH); // Backlight on
- lcd.setCursor (0,0);
- lcd.print("Good afternoon,");
- lcd.setCursor (0,1); // go col 0 of line 1
- lcd.print("gentlemen.");
- delay(1000);
- lcd.setCursor (0,2); // go col 0 of line 2
- lcd.print("I am a HAL 9000 ");
- lcd.setCursor (0,3); // go col 0 of line 3
- lcd.print("computer.");
- delay(4000);
- wipeLines();
- lcd.setCursor (0,0);
- lcd.print("I became operational");
- lcd.setCursor (0,1);
- lcd.print("at the H.A.L. plant ");
- lcd.setCursor (0,2);
- lcd.print("in Urbana, Illinois ");
- lcd.setCursor (0,3);
- lcd.print("on January 12 1992. ");
- delay(4000);
- wipeLines();
- lcd.setCursor (0,0);
- lcd.print("If you'd like to ");
- lcd.setCursor (0,1);
- lcd.print("hear it I can sing ");
- lcd.setCursor (0,2);
- lcd.print("it for you. ");
- lcd.setCursor (0,3);
- lcd.blink(); // Turns on the blinking cursor
- delay(4000);
- wipeLines();
- lcd.noBlink(); // Turns off the blinking cursor
- }
- void wipeLines() {
- for (int y = 0; y < 4; y++) {
- for (int x = 0; x < 20; x++) {
- lcd.setCursor (x,y);
- lcd.print(" ");
- delay(5);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement