PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CustomCharacter.pde 2.8KB

пре 3 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 WR pin to digital pin 10
  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 potentiometer:
  19. * ends to +5V and ground
  20. * wiper to LCD VO pin (pin 3)
  21. * 10K poterntiometer on pin A0
  22. created21 Mar 2011
  23. by Tom Igoe
  24. Based on Adafruit's example at
  25. https://github.com/adafruit/SPI_VFD/blob/master/examples/createChar/createChar.pde
  26. This example code is in the public domain.
  27. http://www.arduino.cc/en/Tutorial/LiquidCrystal
  28. http://www.pjrc.com/teensy/td_libs_LiquidCrystal.html
  29. Also useful:
  30. http://icontexto.com/charactercreator/
  31. */
  32. // include the library code:
  33. #include <LiquidCrystalFast.h>
  34. // initialize the library with the numbers of the interface pins
  35. LiquidCrystalFast lcd(12, 10, 11, 5, 4, 3, 2);
  36. // LCD pins: RS RW EN D4 D5 D6 D7
  37. // make some custom characters:
  38. byte heart[8] = {
  39. 0b00000,
  40. 0b01010,
  41. 0b11111,
  42. 0b11111,
  43. 0b11111,
  44. 0b01110,
  45. 0b00100,
  46. 0b00000
  47. };
  48. byte smiley[8] = {
  49. 0b00000,
  50. 0b00000,
  51. 0b01010,
  52. 0b00000,
  53. 0b00000,
  54. 0b10001,
  55. 0b01110,
  56. 0b00000
  57. };
  58. byte frownie[8] = {
  59. 0b00000,
  60. 0b00000,
  61. 0b01010,
  62. 0b00000,
  63. 0b00000,
  64. 0b00000,
  65. 0b01110,
  66. 0b10001
  67. };
  68. byte armsDown[8] = {
  69. 0b00100,
  70. 0b01010,
  71. 0b00100,
  72. 0b00100,
  73. 0b01110,
  74. 0b10101,
  75. 0b00100,
  76. 0b01010
  77. };
  78. byte armsUp[8] = {
  79. 0b00100,
  80. 0b01010,
  81. 0b00100,
  82. 0b10101,
  83. 0b01110,
  84. 0b00100,
  85. 0b00100,
  86. 0b01010
  87. };
  88. void setup() {
  89. // create a new character
  90. lcd.createChar(0, heart);
  91. // create a new character
  92. lcd.createChar(1, smiley);
  93. // create a new character
  94. lcd.createChar(2, frownie);
  95. // create a new character
  96. lcd.createChar(3, armsDown);
  97. // create a new character
  98. lcd.createChar(4, armsUp);
  99. // set up the lcd's number of columns and rows:
  100. lcd.begin(16, 2);
  101. // Print a message to the lcd.
  102. lcd.print("I ");
  103. lcd.write(0);
  104. lcd.print(" Arduino! ");
  105. lcd.write(1);
  106. }
  107. void loop() {
  108. // read the potentiometer on A0:
  109. int sensorReading = analogRead(A0);
  110. // map the result to 200 - 1000:
  111. int delayTime = map(sensorReading, 0, 1023, 200, 1000);
  112. // set the cursor to the bottom row, 5th position:
  113. lcd.setCursor(4, 1);
  114. // draw the little man, arms down:
  115. lcd.write(3);
  116. delay(delayTime);
  117. lcd.setCursor(4, 1);
  118. // draw him arms up:
  119. lcd.write(4);
  120. delay(delayTime);
  121. }