LCD create character code update

/*
LiquidCrystal Library - Custom Characters

Demonstrates how to add custom characters on an LCD display.
The LiquidCrystal library works with all LCD displays that are
compatible with the Hitachi HD44780 driver. There are many of
them out there, and you can usually tell them by the 16-pin interface.

This sketch prints "I Arduino!" and a little dancing man
to the LCD.

The circuit:

  • LCD RS pin to digital pin 12
  • LCD Enable pin to digital pin 11
  • LCD D4 pin to digital pin 5
  • LCD D5 pin to digital pin 4
  • LCD D6 pin to digital pin 3
  • LCD D7 pin to digital pin 2
  • LCD R/W pin to ground
  • 10K potentiometer:
  • ends to +5V and ground
  • wiper to LCD VO pin (pin 3)
  • 10K poterntiometer on pin A0

created 21 Mar 2011
by Tom Igoe
modified 11 Jan 2017
by Zsolt Biro

Based on Adafruit's example at

This example code is in the public domain.

Also useful:
// alert !! not valid link !!!
http://icontexto.com/charactercreator/

*/

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

// make some custom characters:
byte heart[8] = {
0b00000,
0b01010,
0b11111,
0b11111,
0b11111,
0b01110,
0b00100,
0b00000
};

byte smiley[8] = {
0b00000,
0b00000,
0b01010,
0b00000,
0b00000,
0b10001,
0b01110,
0b00000
};

byte frownie[8] = {
0b00000,
0b00000,
0b01010,
0b00000,
0b00000,
0b00000,
0b01110,
0b10001
};

byte armsDown[8] = {
0b00100,
0b01010,
0b00100,
0b00100,
0b01110,
0b10101,
0b00100,
0b01010
};

byte armsUp[8] = {
0b00100,
0b01010,
0b00100,
0b10101,
0b01110,
0b00100,
0b00100,
0b01010
};

void setup() {
// initialize LCD and set up the number of columns and rows:
lcd.begin(16, 2);

// create a new character
lcd.createChar(0, heart);
// create a new character
lcd.createChar(1, smiley);
// create a new character
lcd.createChar(2, frownie);
// create a new character
lcd.createChar(3, armsDown);
// create a new character
lcd.createChar(4, armsUp);

// upper row , left corner position of the lcd.
lcd.setCursor(0, 0);

// Print a message to the lcd.
lcd.print("I ");
lcd.write(byte(0)); // when calling lcd.write() '0' must be cast as a byte
lcd.print(" Arduino! ");
lcd.write((byte) 1);

}

void loop() {
//write smiley
lcd.setCursor(15, 0);
lcd.write((byte) 1);
// read the potentiometer on A0:
int sensorReading = analogRead(A0);
// map the result to 200 - 1000:
int delayTime = map(sensorReading, 0, 1023, 200, 1000);
// set the cursor to the bottom row, 5th position:
lcd.setCursor(4, 1);
// draw the little man, arms down:
lcd.write(3);
delay(delayTime);
lcd.setCursor(4, 1);
// draw him arms up:
lcd.write(4);
//write heart over smiley
lcd.setCursor(15, 0);
lcd.write((byte) 0);

delay(delayTime);

}

Perhaps you can explain the purpose of your post.

You might also want to find out what 'code tags' are and why you should use them. The forum instructions would be a good place to start.

Don

Don, Hi.

The purpose of the post is in the SUBJECT line.

It is the update of the example file of arduino IDE. It does not work , i mean some part of it.

In red you can see my added lines, which correct the original code and make it work.

File / Examples / LiquidCrystal / CustomCharacter

i hope it is clear now.

regards

floresta:
Perhaps you can explain the purpose of your post.

You might also want to find out what 'code tags' are and why you should use them. The forum instructions would be a good place to start.

Don

I had previously posted to this thread, but it appears to have been lost.
There definitely is an issue in that example, as well as the example here:

The issue is the way the LiquidCrystal library createChar() works, In my view it is bug, but it could be considered a documentation issue. However, if it is not a bug in createChar(), then the example sketch code supplied should be written appropriately to work with the way createChar() works, which it isn't.
(The example code on the LiquidCrystalCreateChar page is not a proper solution and should not be encouraged)

If you want to see more about what is causing issues of print() not working after createChar() see this thread:
https://forum.arduino.cc/index.php?topic=262753.0
And for the detailed explanation about createChar() look at my response in post #10 of that thread.

i.e. the answer is not to move begin() but to do something that puts the display back into DDRAM mode.

Alternatively, you could switch to using my hd44780 library with the hd44780_pinIO class which does not have this issue and you can use print() immediately after calling createChar()
hd44780 can be installed using the IDE library manager, and you can read more about it here:

If you want to get the LiquidCrystal library code for createChar() or the examples that use it changed/fixed, then you will have to file an issue/bug on the Arduino github repository, as the forum is not the place to file bug reports.
You will need to include a concise write up of what the problem is and how to easily replicate it so that the developers can see it and then be able to verify that their updates/fixes to the code resolve the issue.

--- bill