@@ -1010,4 +1010,164 @@ void loop() {
10101010
10111011 thisChar++;
10121012}
1013+ ```
1014+
1015+ ### Custom Character
1016+
1017+ This example demonstrates how to add custom characters on an LCD display.
1018+
1019+ Note that this example requires an additional potentiometer:
1020+ - Outer pins connected to 5V and GND.
1021+ - Inner pin (wiper) connected to A0.
1022+
1023+ This potentiometer controls the ` delayTime ` variable.
1024+
1025+ ``` arduino
1026+ /*
1027+ LiquidCrystal Library - Custom Characters
1028+
1029+ Demonstrates how to add custom characters on an LCD display.
1030+ The LiquidCrystal library works with all LCD displays that are
1031+ compatible with the Hitachi HD44780 driver. There are many of
1032+ them out there, and you can usually tell them by the 16-pin interface.
1033+
1034+ This sketch prints "I <heart> Arduino!" and a little dancing man
1035+ to the LCD.
1036+
1037+ The circuit:
1038+ * LCD RS pin to digital pin 12
1039+ * LCD Enable pin to digital pin 11
1040+ * LCD D4 pin to digital pin 5
1041+ * LCD D5 pin to digital pin 4
1042+ * LCD D6 pin to digital pin 3
1043+ * LCD D7 pin to digital pin 2
1044+ * LCD R/W pin to ground
1045+ * 10K potentiometer:
1046+ * ends to +5V and ground
1047+ * wiper to LCD VO pin (pin 3)
1048+ * 10K poterntiometer on pin A0
1049+
1050+ created 21 Mar 2011
1051+ by Tom Igoe
1052+ modified 11 Nov 2013
1053+ by Scott Fitzgerald
1054+ modified 7 Nov 2016
1055+ by Arturo Guadalupi
1056+
1057+ Based on Adafruit's example at
1058+ https://github.com/adafruit/SPI_VFD/blob/master/examples/createChar/createChar.pde
1059+
1060+ This example code is in the public domain.
1061+ http://www.arduino.cc/en/Tutorial/LiquidCrystalCustomCharacter
1062+
1063+ Also useful:
1064+ http://icontexto.com/charactercreator/
1065+
1066+ */
1067+
1068+ // include the library code:
1069+ #include <LiquidCrystal.h>
1070+
1071+ // initialize the library by associating any needed LCD interface pin
1072+ // with the arduino pin number it is connected to
1073+ const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
1074+ LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
1075+
1076+ // make some custom characters:
1077+ byte heart[8] = {
1078+ 0b00000,
1079+ 0b01010,
1080+ 0b11111,
1081+ 0b11111,
1082+ 0b11111,
1083+ 0b01110,
1084+ 0b00100,
1085+ 0b00000
1086+ };
1087+
1088+ byte smiley[8] = {
1089+ 0b00000,
1090+ 0b00000,
1091+ 0b01010,
1092+ 0b00000,
1093+ 0b00000,
1094+ 0b10001,
1095+ 0b01110,
1096+ 0b00000
1097+ };
1098+
1099+ byte frownie[8] = {
1100+ 0b00000,
1101+ 0b00000,
1102+ 0b01010,
1103+ 0b00000,
1104+ 0b00000,
1105+ 0b00000,
1106+ 0b01110,
1107+ 0b10001
1108+ };
1109+
1110+ byte armsDown[8] = {
1111+ 0b00100,
1112+ 0b01010,
1113+ 0b00100,
1114+ 0b00100,
1115+ 0b01110,
1116+ 0b10101,
1117+ 0b00100,
1118+ 0b01010
1119+ };
1120+
1121+ byte armsUp[8] = {
1122+ 0b00100,
1123+ 0b01010,
1124+ 0b00100,
1125+ 0b10101,
1126+ 0b01110,
1127+ 0b00100,
1128+ 0b00100,
1129+ 0b01010
1130+ };
1131+
1132+ void setup() {
1133+ // initialize LCD and set up the number of columns and rows:
1134+ lcd.begin(16, 2);
1135+
1136+ // create a new character
1137+ lcd.createChar(0, heart);
1138+ // create a new character
1139+ lcd.createChar(1, smiley);
1140+ // create a new character
1141+ lcd.createChar(2, frownie);
1142+ // create a new character
1143+ lcd.createChar(3, armsDown);
1144+ // create a new character
1145+ lcd.createChar(4, armsUp);
1146+
1147+ // set the cursor to the top left
1148+ lcd.setCursor(0, 0);
1149+
1150+ // Print a message to the lcd.
1151+ lcd.print("I ");
1152+ lcd.write(byte(0)); // when calling lcd.write() '0' must be cast as a byte
1153+ lcd.print(" Arduino! ");
1154+ lcd.write((byte)1);
1155+
1156+ }
1157+
1158+ void loop() {
1159+ // read the potentiometer on A0:
1160+ int sensorReading = analogRead(A0);
1161+ // map the result to 200 - 1000:
1162+ int delayTime = map(sensorReading, 0, 1023, 200, 1000);
1163+ // set the cursor to the bottom row, 5th position:
1164+ lcd.setCursor(4, 1);
1165+ // draw the little man, arms down:
1166+ lcd.write(3);
1167+ delay(delayTime);
1168+ lcd.setCursor(4, 1);
1169+ // draw him arms up:
1170+ lcd.write(4);
1171+ delay(delayTime);
1172+ }
10131173```
0 commit comments