Arduino Playground is read-only starting December 31st, 2018. For more info please look at this Forum Post

serLCD

createChar()

Description

Create a custom character (gylph) for use on the LCD. Up to eight characters of 5x8 pixels are supported (numbered 1 to 8). The appearance of each custom character is specified by an array of eight bytes, one for each row. The five least significant bits of each byte determine the pixels in that row.

Syntax

lcd.createChar(num, data)

Parameters

lcd: a variable of type serLCD

num: which character to create (1 to 8)

data: the character's pixel data

Example 1

  1. /*
  2.   serLCD - Create custom character example 1
  3.            This example creates a custom smiley face
  4.            character.
  5. */
  6. #include <SoftwareSerial.h>
  7. #include <serLCD.h>
  8.  
  9. // Set pin to the LCD's rxPin
  10. int pin = 2;
  11.  
  12. serLCD lcd(pin);
  13.  
  14. byte smiley[8] = {
  15.   B00000,
  16.   B10001,
  17.   B00000,
  18.   B00000,
  19.   B10001,
  20.   B01110,
  21.   B00000,
  22. };
  23.  
  24. void setup()
  25. {
  26.   lcd.createChar(1, smiley);
  27.   lcd.printCustomChar(1);
  28. }
  29.  
  30. void loop() {}

Example 2

  1. /*
  2.   serLCD - Create custom character example 2
  3.            This example creates 8 custom characters
  4.            resulting in a bar graph.
  5. */
  6. #include <SoftwareSerial.h>
  7. #include <serLCD.h>
  8.  
  9. // Set pin to the LCD's rxPin
  10. int pin = 2;
  11.  
  12. serLCD lcd(pin);
  13.  
  14. byte bars[8][8] = {
  15.   {B00000,B00000,B00000,B00000,B00000,B00000,B00000,B11111},
  16.   {B00000,B00000,B00000,B00000,B00000,B00000,B11111,B11111},
  17.   {B00000,B00000,B00000,B00000,B00000,B11111,B11111,B11111},
  18.   {B00000,B00000,B00000,B00000,B11111,B11111,B11111,B11111},
  19.   {B00000,B00000,B00000,B11111,B11111,B11111,B11111,B11111},
  20.   {B00000,B00000,B11111,B11111,B11111,B11111,B11111,B11111},
  21.   {B00000,B11111,B11111,B11111,B11111,B11111,B11111,B11111},
  22.   {B11111,B11111,B11111,B11111,B11111,B11111,B11111,B11111}
  23. };
  24.  
  25. void setup()
  26. {
  27.   for (int i=1; i < 9; i++){
  28.     lcd.createChar(i, bars[i-1]);
  29.   }
  30. }
  31.  
  32. void loop()
  33. {
  34.   for (int i=1; i < 9; i++){
  35.     lcd.printCustomChar(i);
  36.   }
  37. while(1); // stop looping
  38. }