Advertisement
Guest User

Untitled

a guest
Nov 26th, 2015
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. /* YourDuino.com Example Software Sketch
  2. 16 character 2 line I2C Display
  3. Backpack Interface labelled "A0 A1 A2" at lower right.
  4. ..and
  5. Backpack Interface labelled "YwRobot Arduino LCM1602 IIC V1"
  6. MOST use address 0x27, a FEW use 0x3F
  7. terry@yourduino.com */
  8.  
  9. /*-----( Import needed libraries )-----*/
  10. #include <Wire.h> // Comes with Arduino IDE
  11. // Get the LCD I2C Library here:
  12. // https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads
  13. // Move any other LCD libraries to another folder or delete them
  14. // See Library "Docs" folder for possible commands etc.
  15. #include <LiquidCrystal_I2C.h>
  16.  
  17. /*-----( Declare Constants )-----*/
  18. /*-----( Declare objects )-----*/
  19. // set the LCD address to 0x27 for a 16 chars 2 line display
  20. // A FEW use address 0x3F
  21. // Set the pins on the I2C chip used for LCD connections:
  22. // addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
  23. LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
  24.  
  25. /*-----( Declare Variables )-----*/
  26. //NONE
  27.  
  28. void setup() /*----( SETUP: RUNS ONCE )----*/
  29. {
  30. Serial.begin(9600); // Used to type in characters
  31.  
  32. lcd.begin(16,2); // initialize the lcd for 16 chars 2 lines, turn on backlight
  33.  
  34. // ------- Quick 3 blinks of backlight -------------
  35. for(int i = 0; i< 3; i++)
  36. {
  37. lcd.backlight();
  38. delay(250);
  39. lcd.noBacklight();
  40. delay(250);
  41. }
  42. lcd.backlight(); // finish with backlight on
  43.  
  44. //-------- Write characters on the display ------------------
  45. // NOTE: Cursor Position: (CHAR, LINE) start at 0
  46. lcd.setCursor(0,0); //Start at character 4 on line 0
  47. lcd.print("Hello, world!");
  48. delay(1000);
  49. lcd.setCursor(0,1);
  50. lcd.print("HI!YourDuino.com");
  51. delay(8000);
  52.  
  53. // Wait and then tell user they can start the Serial Monitor and type in characters to
  54. // Display. (Set Serial Monitor option to "No Line Ending")
  55. lcd.clear();
  56. lcd.setCursor(0,0); //Start at character 0 on line 0
  57. lcd.print("Use Serial Mon");
  58. lcd.setCursor(0,1);
  59. lcd.print("Type to display");
  60.  
  61.  
  62. }/*--(end setup )---*/
  63.  
  64.  
  65. void loop() /*----( LOOP: RUNS CONSTANTLY )----*/
  66. {
  67. {
  68. // when characters arrive over the serial port...
  69. if (Serial.available()) {
  70. // wait a bit for the entire message to arrive
  71. delay(100);
  72. // clear the screen
  73. lcd.clear();
  74. // read all the available characters
  75. while (Serial.available() > 0) {
  76. // display each character to the LCD
  77. lcd.write(Serial.read());
  78. }
  79. }
  80. }
  81.  
  82. }/* --(end main loop )-- */
  83.  
  84.  
  85. /* ( THE END ) */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement