PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

148 linhas
3.0KB

  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. modified 7 Nov 2016
  26. by Arturo Guadalupi
  27. Based on Adafruit's example at
  28. https://github.com/adafruit/SPI_VFD/blob/master/examples/createChar/createChar.pde
  29. This example code is in the public domain.
  30. http://www.arduino.cc/en/Tutorial/LiquidCrystalCustomCharacter
  31. Also useful:
  32. http://icontexto.com/charactercreator/
  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. // make some custom characters:
  41. byte heart[8] = {
  42. 0b00000,
  43. 0b01010,
  44. 0b11111,
  45. 0b11111,
  46. 0b11111,
  47. 0b01110,
  48. 0b00100,
  49. 0b00000
  50. };
  51. byte smiley[8] = {
  52. 0b00000,
  53. 0b00000,
  54. 0b01010,
  55. 0b00000,
  56. 0b00000,
  57. 0b10001,
  58. 0b01110,
  59. 0b00000
  60. };
  61. byte frownie[8] = {
  62. 0b00000,
  63. 0b00000,
  64. 0b01010,
  65. 0b00000,
  66. 0b00000,
  67. 0b00000,
  68. 0b01110,
  69. 0b10001
  70. };
  71. byte armsDown[8] = {
  72. 0b00100,
  73. 0b01010,
  74. 0b00100,
  75. 0b00100,
  76. 0b01110,
  77. 0b10101,
  78. 0b00100,
  79. 0b01010
  80. };
  81. byte armsUp[8] = {
  82. 0b00100,
  83. 0b01010,
  84. 0b00100,
  85. 0b10101,
  86. 0b01110,
  87. 0b00100,
  88. 0b00100,
  89. 0b01010
  90. };
  91. void setup() {
  92. // initialize LCD and set up the number of columns and rows:
  93. lcd.begin(16, 2);
  94. // create a new character
  95. lcd.createChar(0, heart);
  96. // create a new character
  97. lcd.createChar(1, smiley);
  98. // create a new character
  99. lcd.createChar(2, frownie);
  100. // create a new character
  101. lcd.createChar(3, armsDown);
  102. // create a new character
  103. lcd.createChar(4, armsUp);
  104. // set the cursor to the top left
  105. lcd.setCursor(0, 0);
  106. // Print a message to the lcd.
  107. lcd.print("I ");
  108. lcd.write(byte(0)); // when calling lcd.write() '0' must be cast as a byte
  109. lcd.print(" Arduino! ");
  110. lcd.write((byte)1);
  111. }
  112. void loop() {
  113. // read the potentiometer on A0:
  114. int sensorReading = analogRead(A0);
  115. // map the result to 200 - 1000:
  116. int delayTime = map(sensorReading, 0, 1023, 200, 1000);
  117. // set the cursor to the bottom row, 5th position:
  118. lcd.setCursor(4, 1);
  119. // draw the little man, arms down:
  120. lcd.write(3);
  121. delay(delayTime);
  122. lcd.setCursor(4, 1);
  123. // draw him arms up:
  124. lcd.write(4);
  125. delay(delayTime);
  126. }