CustomCharacter.ino 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. LiquidCrystal Library - Custom Characters
  3. Demonstrates how to add custom characters on an LCD display.
  4. The LiquidCrystal library works with all LCD displays that are
  5. compatible with the Hitachi HD44780 driver. There are many of
  6. them out there, and you can usually tell them by the 16-pin interface.
  7. This sketch prints "I <heart> Arduino!" and a little dancing man
  8. to the LCD.
  9. The circuit:
  10. * LCD RS pin to digital pin 12
  11. * LCD Enable pin to digital pin 11
  12. * LCD D4 pin to digital pin 5
  13. * LCD D5 pin to digital pin 4
  14. * LCD D6 pin to digital pin 3
  15. * LCD D7 pin to digital pin 2
  16. * LCD R/W pin to ground
  17. * 10K potentiometer:
  18. * ends to +5V and ground
  19. * wiper to LCD VO pin (pin 3)
  20. * 10K poterntiometer on pin A0
  21. created 21 Mar 2011
  22. by Tom Igoe
  23. modified 11 Nov 2013
  24. by Scott Fitzgerald
  25. Based on Adafruit's example at
  26. https://github.com/adafruit/SPI_VFD/blob/master/examples/createChar/createChar.pde
  27. This example code is in the public domain.
  28. http://www.arduino.cc/en/Tutorial/LiquidCrystal
  29. Also useful:
  30. http://icontexto.com/charactercreator/
  31. */
  32. // include the library code:
  33. #include <LiquidCrystal.h>
  34. // initialize the library with the numbers of the interface pins
  35. LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
  36. // make some custom characters:
  37. byte heart[8] = {
  38. 0b00000,
  39. 0b01010,
  40. 0b11111,
  41. 0b11111,
  42. 0b11111,
  43. 0b01110,
  44. 0b00100,
  45. 0b00000
  46. };
  47. byte smiley[8] = {
  48. 0b00000,
  49. 0b00000,
  50. 0b01010,
  51. 0b00000,
  52. 0b00000,
  53. 0b10001,
  54. 0b01110,
  55. 0b00000
  56. };
  57. byte frownie[8] = {
  58. 0b00000,
  59. 0b00000,
  60. 0b01010,
  61. 0b00000,
  62. 0b00000,
  63. 0b00000,
  64. 0b01110,
  65. 0b10001
  66. };
  67. byte armsDown[8] = {
  68. 0b00100,
  69. 0b01010,
  70. 0b00100,
  71. 0b00100,
  72. 0b01110,
  73. 0b10101,
  74. 0b00100,
  75. 0b01010
  76. };
  77. byte armsUp[8] = {
  78. 0b00100,
  79. 0b01010,
  80. 0b00100,
  81. 0b10101,
  82. 0b01110,
  83. 0b00100,
  84. 0b00100,
  85. 0b01010
  86. };
  87. void setup() {
  88. // initialize LCD and set up the number of columns and rows:
  89. lcd.begin(16, 2);
  90. // create a new character
  91. lcd.createChar(0, heart);
  92. // create a new character
  93. lcd.createChar(1, smiley);
  94. // create a new character
  95. lcd.createChar(2, frownie);
  96. // create a new character
  97. lcd.createChar(3, armsDown);
  98. // create a new character
  99. lcd.createChar(4, armsUp);
  100. // Print a message to the lcd.
  101. lcd.print("I ");
  102. lcd.write(byte(0)); // when calling lcd.write() '0' must be cast as a byte
  103. lcd.print(" Arduino! ");
  104. lcd.write((byte) 1);
  105. }
  106. void loop() {
  107. // read the potentiometer on A0:
  108. int sensorReading = analogRead(A0);
  109. // map the result to 200 - 1000:
  110. int delayTime = map(sensorReading, 0, 1023, 200, 1000);
  111. // set the cursor to the bottom row, 5th position:
  112. lcd.setCursor(4, 1);
  113. // draw the little man, arms down:
  114. lcd.write(3);
  115. delay(delayTime);
  116. lcd.setCursor(4, 1);
  117. // draw him arms up:
  118. lcd.write(4);
  119. delay(delayTime);
  120. }