Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.23 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2.  
  3. // initialize the library with the numbers of the interface pins
  4. LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // create an lcd object and assign the pins
  5.  
  6. void setup() {
  7. lcd.begin(16, 2); // Set the display to 16 columns and 2 rows
  8. }
  9. void loop() {
  10. // run the 7 demo routines
  11. basicPrintDemo();
  12. displayOnOffDemo();
  13. setCursorDemo();
  14. scrollLeftDemo();
  15. scrollRightDemo();
  16. cursorDemo();
  17. createGlyphDemo();
  18. }
  19. void basicPrintDemo() {
  20. lcd.clear(); // Clear the display
  21. lcd.print("Print Dasar"); // print some text
  22. delay(2000);
  23. }
  24. void displayOnOffDemo() {
  25. lcd.clear(); // Clear the display
  26. lcd.print("Mendisplay On/Off"); // print some text
  27. for(int x=0; x < 3; x++) { // loop 3 times
  28. lcd.noDisplay(); // turn display off
  29. delay(1000);
  30. lcd.display(); // turn it back on again
  31. delay(1000);
  32. }
  33. }
  34. void setCursorDemo() {
  35. lcd.clear(); // Clear the display
  36. lcd.print("SetCursor Demo"); // print some text
  37. delay(1000);
  38. lcd.clear(); // Clear the display lcd.setCursor(5,0); // cursor at column 5 row 0
  39. lcd.print("5,0");
  40. delay(2000);
  41. lcd.setCursor(10,1); // cursor at column 10 row 1
  42. lcd.print("10,1");
  43. delay(2000);
  44. lcd.setCursor(3,1); // cursor at column 3 row 1
  45. lcd.print("3,1");
  46. delay(2000);
  47. }
  48. void scrollLeftDemo() {
  49. lcd.clear(); // Clear the display
  50. lcd.print("Scroll Left Demo");
  51. delay(1000);
  52. lcd.clear(); // Clear the display
  53. lcd.setCursor(7,0);
  54. lcd.print("Beginning");
  55. lcd.setCursor(9,1);
  56. lcd.print("Arduino");
  57. delay(1000);
  58. for(int x=0; x<16; x++) {
  59. lcd.scrollDisplayLeft(); // scroll display left 16 times
  60. delay(250);
  61. }
  62. }
  63. void scrollRightDemo() {
  64. lcd.clear(); // Clear the display
  65. lcd.print("Scroll Right");
  66. lcd.setCursor(0,1);
  67. lcd.print("Demo");
  68. delay(1000);
  69. lcd.clear(); // Clear the display
  70. lcd.print("Beginning");
  71. lcd.setCursor(0,1);
  72. lcd.print("Arduino");
  73. delay(1000);
  74. for(int x=0; x<16; x++) {
  75. lcd.scrollDisplayRight(); // scroll display right 16 times
  76. delay(250);
  77. }
  78. }
  79.  
  80. void cursorDemo() {
  81. lcd.clear(); // Clear the display
  82. lcd.cursor(); // Enable cursor visible
  83. lcd.print("Cursor On");
  84. delay(3000);
  85. lcd.clear(); // Clear the display
  86. lcd.noCursor(); // cursor invisible
  87. lcd.print("Cursor Off");
  88. delay(3000);
  89. lcd.clear(); // Clear the display
  90. lcd.cursor(); // cursor visible
  91. lcd.blink(); // cursor blinking
  92. lcd.print("Cursor Blink On");
  93. delay(3000);
  94. lcd.noCursor(); // cursor invisible
  95. lcd.noBlink(); // blink off
  96. }
  97.  
  98. void createGlyphDemo() {
  99. lcd.clear();
  100. byte happy[8] = { // create byte array with happy face
  101. B00000,
  102. B00000,
  103. B10001,
  104. B00000,
  105. B10001,
  106. B01110,
  107. B00000,
  108. B00000};
  109.  
  110. byte sad[8] = { // create byte array with sad face
  111. B00000,
  112. B00000,
  113. B10001,
  114. B00000,
  115. B01110,
  116. B10001,
  117. B00000,
  118. B00000};
  119.  
  120. byte frownie[8] = {
  121. 0b00000,
  122. 0b00000,
  123. 0b01010,
  124. 0b00000,
  125. 0b00000,
  126. 0b00000,
  127. 0b01110,
  128. 0b10001
  129. };
  130.  
  131. byte armsUp[8] = {
  132. 0b00100,
  133. 0b01010,
  134. 0b00100,
  135. 0b10101,
  136. 0b01110,
  137. 0b00100,
  138. 0b00100,
  139. 0b01010
  140. };
  141.  
  142. lcd.createChar(0, happy); // create custom character 0
  143.  
  144. for(int x=0; x<5; x++) { // loop animation 5 times
  145. lcd.setCursor(8,0);
  146. lcd.write(happy[8]);
  147. delay(1000);
  148. }
  149.  
  150. lcd.createChar(0, sad);
  151. for(int x=0; x<5; x++) { // loop animation 5 times
  152. lcd.setCursor(8,0);
  153. lcd.write(sad[8]);
  154. delay(1000);
  155. }
  156.  
  157. lcd.createChar(0, frownie);
  158. for(int x=0; x<5; x++) { // loop animation 5 times
  159. lcd.setCursor(8,0);
  160. lcd.write(frownie[8]);
  161. delay(1000);
  162. }
  163. lcd.createChar(0, armsUp);
  164. for(int x=0; x<5; x++) { // loop animation 5 times
  165. lcd.setCursor(8,0);
  166. lcd.write(armsUp[8]);
  167. delay(1000);
  168. }
  169. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement