Scroll.ino 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. LiquidCrystal Library - scrollDisplayLeft() and scrollDisplayRight()
  3. Demonstrates the use a 16x2 LCD display. The LiquidCrystal
  4. library works with all LCD displays that are compatible with the
  5. Hitachi HD44780 driver. There are many of them out there, and you
  6. can usually tell them by the 16-pin interface.
  7. This sketch prints "Hello World!" to the LCD and uses the
  8. scrollDisplayLeft() and scrollDisplayRight() methods to scroll
  9. the text.
  10. The circuit:
  11. * LCD RS pin to digital pin 12
  12. * LCD Enable pin to digital pin 11
  13. * LCD D4 pin to digital pin 5
  14. * LCD D5 pin to digital pin 4
  15. * LCD D6 pin to digital pin 3
  16. * LCD D7 pin to digital pin 2
  17. * LCD R/W pin to ground
  18. * 10K resistor:
  19. * ends to +5V and ground
  20. * wiper to LCD VO pin (pin 3)
  21. Library originally added 18 Apr 2008
  22. by David A. Mellis
  23. library modified 5 Jul 2009
  24. by Limor Fried (http://www.ladyada.net)
  25. example added 9 Jul 2009
  26. by Tom Igoe
  27. modified 22 Nov 2010
  28. by Tom Igoe
  29. modified 7 Nov 2016
  30. by Arturo Guadalupi
  31. This example code is in the public domain.
  32. http://www.arduino.cc/en/Tutorial/LiquidCrystalScroll
  33. */
  34. // include the library code:
  35. #include <LiquidCrystal.h>
  36. // initialize the library by associating any needed LCD interface pin
  37. // with the arduino pin number it is connected to
  38. const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
  39. LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
  40. void setup() {
  41. // set up the LCD's number of columns and rows:
  42. lcd.begin(16, 2);
  43. // Print a message to the LCD.
  44. lcd.print("hello, world!");
  45. delay(1000);
  46. }
  47. void loop() {
  48. // scroll 13 positions (string length) to the left
  49. // to move it offscreen left:
  50. for (int positionCounter = 0; positionCounter < 13; positionCounter++) {
  51. // scroll one position left:
  52. lcd.scrollDisplayLeft();
  53. // wait a bit:
  54. delay(150);
  55. }
  56. // scroll 29 positions (string length + display length) to the right
  57. // to move it offscreen right:
  58. for (int positionCounter = 0; positionCounter < 29; positionCounter++) {
  59. // scroll one position right:
  60. lcd.scrollDisplayRight();
  61. // wait a bit:
  62. delay(150);
  63. }
  64. // scroll 16 positions (display length + string length) to the left
  65. // to move it back to center:
  66. for (int positionCounter = 0; positionCounter < 16; positionCounter++) {
  67. // scroll one position left:
  68. lcd.scrollDisplayLeft();
  69. // wait a bit:
  70. delay(150);
  71. }
  72. // delay at the end of the full loop:
  73. delay(1000);
  74. }