Advertisement
Guest User

Arduino: I2C LCD 16x2 controller

a guest
Dec 21st, 2014
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.82 KB | None | 0 0
  1. // http://arduinoinfo.info/
  2. /* YourDuino.com Example Software Sketch
  3.  20 character 4 line I2C Display or 16 character 2 line I2C Display
  4.  ANOTHER NEW TYPE Marked "LCM1602 IIC  A0 A1 A2"
  5.  A0-A1-A2 are grounded so I2C Address is 0x20  
  6.  terry@yourduino.com */
  7. /*-----( Import needed libraries )-----*/
  8. #include <Wire.h>
  9. #include <LCD.h>
  10. #include <LiquidCrystal_I2C.h>  // F Malpartida's NewLiquidCrystal library
  11. //Download: https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads
  12. // Move original LiquidCrystal library elsewhere, copy this in it's place
  13. /*-----( Declare Constants )-----*/
  14. #define I2C_ADDR    0x38  // Define I2C Address for the PCF8574T
  15. //---(Following are the PCF8574 pin assignments to LCD connections )----
  16. // This are different than earlier/different I2C LCD displays
  17. #define BACKLIGHT_PIN  3
  18. #define En_pin  2
  19. #define Rw_pin  1
  20. #define Rs_pin  0
  21. #define D4_pin  4
  22. #define D5_pin  5
  23. #define D6_pin  6
  24. #define D7_pin  7
  25.  
  26. #define  LED_OFF  1
  27. #define  LED_ON  0
  28.  
  29. /*-----( Declare objects )-----*/  
  30. LiquidCrystal_I2C  lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
  31.  
  32. void setup()   /*----( SETUP: RUNS ONCE )----*/
  33. {
  34.  // lcd.begin (20,4);  // initialize the lcd
  35.   lcd.begin (16,2);  // initialize the lcd
  36. // Switch on the backlight
  37. //  lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
  38. //  lcd.setBacklight(LED_ON);
  39. }// END Setup
  40.  
  41. void loop()   /*----( LOOP: RUNS OVER AND OVER AGAIN )----*/
  42. {
  43.  
  44. // Reset the display  
  45.   lcd.clear();
  46.   delay(1000);
  47.   lcd.home();
  48.  
  49. // Print our characters on the LCD
  50.   //lcd.backlight();  //Backlight ON if under program control
  51.   delay(1000);
  52.   lcd.setCursor(2,0); //Start at character 2 on line 0
  53.   lcd.print("Hello, Viktor!");
  54.   delay(1000);
  55.  
  56.   lcd.setCursor(0,1);
  57.   lcd.print("HomoCyberneticus");
  58.   delay(1000);  
  59. } // END Loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement