5. Orangutan LCD

The OrangutanLCD class and the C functions in this section provide a variety of ways of displaying data to the LCD screen of an 3pi or Orangutan LV-168, providing an essential tool for user interfaces and debugging. The library implements the standard 4-bit HD44780 protocol, and it uses the busy-wait-flag feature to avoid the unnecessarily long delays present in other 4-bit LCD Arduino libraries. It is designed to gracefully handle alternate use of the four LCD data lines. It will change their data direction registers and output states only when needed for an LCD command, after which it will immediately restore the registers to their previous states. This allows the LCD data lines to function, for example, as pushbutton inputs and an LED driver on the 3pi and the Orangutan LV-168.

For C and C++ users, the standard C function printf() is made available. See below for more information.

For a higher level overview of this library and example programs that show how this library can be used, please see Section 5.c of the guide to Programming Orangutans from the Arduino Environment or Section 6.e of the Pololu AVR C/C++ Library User’s Guide.

Reference

C++ and Arduino methods are shown in red.

C functions are shown in green.

static void OrangutanLCD::clear()

void clear()

Clears the display and returns the cursor to the upper-left corner (0, 0).

void OrangutanLCD::initPrintf()

void lcd_init_printf()

Initializes the display for use with the standard C function printf(). This is not available in the Arduino environment. See the avr-libc manual for more information on how to use printf with an AVR, and please note that using printf() will consume a significant amount of your Orangutan’s resources.

static void OrangutanLCD::print(unsigned char character)

Prints a single ASCII character to the display at the current cursor position.

static void OrangutanLCD::print(char character)

void print_character(char character)

Prints a single ASCII character to the display at the current cursor position. This is the same as the unsigned char version above.

Example:

OrangutanLCD::print('A');

static void OrangutanLCD::print(const char *str)

void print(const char *str)

Prints a zero-terminated string of ASCII characters to the display starting at the current cursor position. The string will not wrap or otherwise span lines.

Example:

OrangutanLCD::print("Hello!");

static void OrangutanLCD::printFromProgramSpace(const char *str)

void print_from_program_space(const char *str)

Prints a string stored in program memory. This can help save a few bytes of RAM for each message that your program prints. Even if you use the normal print() function, the strings will be initially stored in program space anyway, so it should never hurt you to use this function.

Example:

#include <avr/pgmspace.h>
const char message[] PROGMEM = "Hello!";

void someFunction()
{
  OrangutanLCD::printFromProgramSpace(message);
}

static void OrangutanLCD::print(int value)

Prints the specified signed integer (2-byte) value to the display at the current cursor position. It will not wrap or otherwise span lines. There is no C version of this method, but print_long(value) should be sufficient.

Example:

OrangutanLCD::print(-25);

static void OrangutanLCD::print(long value)

void print_long(long value)

Prints the specified signed long (4-byte) value to the display at the current cursor position. It will not wrap or otherwise span lines.

static void OrangutanLCD::print(unsigned int value)

Prints the specified unsigned integer (2-byte) value to the display at the current cursor position. The value will not wrap or otherwise span lines and will always be positive.

static void OrangutanLCD::print(unsigned long value)

void print_unsigned_long(long value)

Prints the specified unsigned long (4-byte) value to the display at the current cursor position. The value will not wrap or otherwise span lines and will always be positive.

static void OrangutanLCD::printHex(unsigned int value)

void print_hex(unsigned int value)

Prints the specified two-byte value in hex to the display at the current cursor position. The value will not wrap or otherwise span lines.

static void OrangutanLCD::printHex(unsigned char value)

void print_hex_byte(unsigned char value)

Prints the specified byte value in hex to the display at the current cursor position. The value will not wrap or otherwise span lines.

static void OrangutanLCD::printBinary(unsigned char value)

void print_binary(unsigned char value)

Prints the specified byte in binary to the display at the current cursor position. The value will not wrap or otherwise span lines.

static void OrangutanLCD::gotoXY(unsigned char x, unsigned char y)

void lcd_goto_xy(int col, int row)

Moves the cursor to the specified (x, y) location on the LCD. The top line is y = 0 and the leftmost character column is x = 0, so you can return to the upper-left home position by calling lcd.gotoXY(0, 0), and you can go to the start of the second LCD line by calling lcd.gotoXY(0, 1);

static void OrangutanLCD::showCursor(unsigned char cursorType)

void lcd_show_cursor()

Displays the cursor as either a blinking or solid block. This library defines literals CURSOR_BLINKING and CURSOR_SOLID for use as an argument to this method.

static void OrangutanLCD::hideCursor()

void lcd_hide_cursor()

Hides the cursor.

static void OrangutanLCD::moveCursor(unsigned char direction, unsigned char distance)

void lcd_move_cursor(unsigned char direction, unsigned char num)

Moves the cursor left or right by distance spaces. This library defines literals LCD_LEFT and LCD_RIGHT for use as a direction argument to this method.

static void OrangutanLCD::scroll(unsigned char direction, unsigned char distance, unsigned int delay_time)

void lcd_scroll(unsigned char direction, unsigned char num, unsigned int delay_time)

Shifts the display left or right by distance spaces, delaying for delay_time milliseconds between each shift. This library defines literals LCD_LEFT and LCD_RIGHT for use as a direction argument to this method. Execution does not return from this method until the shift is complete.

static void OrangutanLCD::loadCustomCharacter(const char *picture_ptr, unsigned char number)

void lcd_load_custom_character(const char *picture_ptr, unsigned char number)

Loads a custom character drawing into the memory of the LCD. The parameter ‘number’ is a character value between 0 and 7, which represents the character that will be customized. That is, lcd.print((char)number) or print_character(number) will display this drawing in the future.

Note: the clear() method must be called before these characters are used.

The pointer picture_ptr must be a pointer to an 8 byte array in program space containing the picture data. Bit 0 of byte 0 is the upper-right pixel of the 5×8 character, and bit 4 of byte 7 is the lower-left pixel. The example below demonstrates how to construct this kind of array.

Example:

#include <avr/pgmspace.h>
// the PROGMEM macro comes from the pgmspace.h header file
// and causes the smile pointer to point to program memory instead
// of RAM
const char smile[] PROGMEM = {
  0b00000,
  0b01010,
  0b01010,
  0b01010,
  0b00000,
  0b10001,
  0b01110,
  0b00000
};

void setup()
{
  // set character 3 to a smiley face
  OrangutanLCD::loadCustomCharacter(smile, 3);

  // clear the lcd (this must be done before we can use the above character)
  OrangutanLCD::clear();

  // display the character
  OrangutanLCD::print((char)3);
}