AVRTools
A Library for the AVR ATmega328 and ATmega2560 Microcontrollers
|
This class provides a high-level interface via I2C to an LCD such as those offered by AdaFruit and SparkFun. Specifically, it communicates via I2C with an MCP23017 that drives an HD44780U controlling an LCD. It also lets you detect button presses on the 5-button keypad generally assocaited with such devices. More...
#include <I2cLcd.h>
Public Types | |
enum | { kButton_Select, kButton_Right, kButton_Down, kButton_Up, kButton_Left } |
enum | { kBacklight_Red, kBacklight_Yellow, kBacklight_Green, kBacklight_Teal, kBacklight_Blue, kBacklight_Violet, kBacklight_White } |
enum | IntegerOutputBase { kBin = 2, kOct = 8, kDec = 10, kHex = 16 } |
An enumeration that defines the number that will be used as the base for representing integer quantities as a string of characters. More... | |
Public Member Functions | |
I2cLcd () | |
Constructor simply initializes some internal bookkeeping. | |
int | init () |
Initialize the I2cLcd object. This must be called before using the I2cLcd, or calling any of the other member functions. The I2C system must be initialized before calling this function (by calling I2cMaster::start() from I2cMaster.h). More... | |
void | clear () |
Clear the display (all rows, all columns). | |
void | home () |
Move the cursor home (the top row, left column). | |
void | displayTopRow (const char *str) |
Display a C-string on the top row. More... | |
void | displayBottomRow (const char *str) |
Display a C-string on the bottom row. More... | |
void | clearTopRow () |
Clear the top row. | |
void | clearBottomRow () |
Clear the bottom row. | |
void | displayOff () |
Turn the display off. | |
void | displayOn () |
Turn the display on. | |
void | blinkOff () |
Do not blink the cursor. | |
void | blinkOn () |
Blink the cursor. | |
void | cursorOff () |
Hide the cursor. | |
void | cursorOn () |
Display the cursor. | |
void | scrollDisplayLeft () |
Scroll the display to the left. | |
void | scrollDisplayRight () |
Scroll the display to the right. | |
void | autoscrollOn () |
Turn on automatic scrolling of the display. | |
void | autoscrollOff () |
Turn off automatic scrolling of the display. | |
void | setCursor (uint8_t row, uint8_t col) |
Move the cursor the a particular row and column. More... | |
int | setBacklight (uint8_t color) |
Set the backlight to a given color. Set a black-and-white LCD display to White if you want to have a backlight. More... | |
void | command (uint8_t cmd) |
Pass a command to the LCD. More... | |
uint8_t | readButtons () |
Read the state of the buttons associated with the LCD display. More... | |
virtual size_t | write (char c) |
Write a single character to the LCD at the current cursor location. This implements the pure virtual function Writer::write( char c ). More... | |
virtual size_t | write (const char *str) |
Write a C-string to the LCD at the current cursor location. This implements the pure virtual function Writer::write( const char* str ). More... | |
virtual size_t | write (const char *buffer, size_t size) |
Write a given number of characters from a buffer to the LCD at the current cursor location. This implements the pure virtual function Writer::write( const char* buffer, size_t size ). More... | |
virtual size_t | write (const uint8_t *buffer, size_t size) |
Write a given number of bytes from a buffer to the LCD at the current cursor location. This implements the pure virtual function Writer::write( const uint8_t* buffer, size_t size ). More... | |
virtual void | flush () |
This function does nothing. It simply implements the pure virtual function Writer::flush(). | |
size_t | print (const char *str, bool addLn=false) |
Print a null-terminated string to the output stream, with or without adding a new line character at the end. More... | |
size_t | print (const uint8_t *buf, size_t size, bool addLn=false) |
Print a number of bytes to the output stream, with or without adding a new line character at the end. More... | |
size_t | print (char c, bool addLn=false) |
Print a single character to the output stream, with or without adding a new line character at the end. More... | |
size_t | print (int8_t n, int base=kDec, bool addLn=false) |
Print an 8-bit integer to the output stream, with or without adding a new line character at the end. More... | |
size_t | print (uint8_t n, int base=kDec, bool addLn=false) |
Print an 8-bit unsigned integer to the output stream, with or without adding a new line character at the end. More... | |
size_t | print (int n, int base=kDec, bool addLn=false) |
Print an integer to the output stream, with or without adding a new line character at the end. More... | |
size_t | print (unsigned int n, int base=kDec, bool addLn=false) |
Print an unsigned integer to the output stream, with or without adding a new line character at the end. More... | |
size_t | print (long n, int base=kDec, bool addLn=false) |
Print a long integer to the output stream, with or without adding a new line character at the end. More... | |
size_t | print (unsigned long n, int base=kDec, bool addLn=false) |
Print an unsigned long integer to the output stream, with or without adding a new line character at the end. More... | |
size_t | print (double d, int digits=2, bool addLn=false) |
Print a floating point number to the output stream, with or without adding a new line character at the end. More... | |
size_t | println (const char *str) |
Print a null-terminated string to the output stream, adding a new line character at the end. More... | |
size_t | println (const uint8_t *buf, size_t size) |
Print a number of bytes to the output stream, adding a new line character at the end. More... | |
size_t | println (char c) |
Print a single character to the output stream, adding a new line character at the end. More... | |
size_t | println (int8_t n, int base=kDec) |
Print an 8-bit integer to the output stream, adding a new line character at the end. More... | |
size_t | println (uint8_t n, int base=kDec) |
Print an 8-bit unsigned integer to the output stream, adding a new line character at the end. More... | |
size_t | println (int n, int base=kDec) |
Print an integer to the output stream, adding a new line character at the end. More... | |
size_t | println (unsigned int n, int base=kDec) |
Print an unsigned integer to the output stream, adding a new line character at the end. More... | |
size_t | println (long n, int base=kDec) |
Print a long integer to the output stream, adding a new line character at the end. More... | |
size_t | println (unsigned long n, int base=kDec) |
Print an unsigned long integer to the output stream, adding a new line character at the end. More... | |
size_t | println (double d, int digits=2) |
Print a floating point number to the output stream, adding a new line character at the end. More... | |
size_t | println () |
Print a new line to the output stream. | |
This class provides a high-level interface via I2C to an LCD such as those offered by AdaFruit and SparkFun. Specifically, it communicates via I2C with an MCP23017 that drives an HD44780U controlling an LCD. It also lets you detect button presses on the 5-button keypad generally assocaited with such devices.
This class derives from Writer, allowing you to write to the LCD much as it if were a serial device.
To use these features, include I2cLcd.h in your source code and link against I2cLcd.cpp and I2cMaster.cpp, and initialize the I2C hardware by calling I2cMaster::start().
anonymous enum |
anonymous enum |
These constants are used to set the backlight color on the LCD.
|
inherited |
An enumeration that defines the number that will be used as the base for representing integer quantities as a string of characters.
void I2cLcd::command | ( | uint8_t | cmd | ) |
Pass a command to the LCD.
cmd
a valid command to send to the HD44780U. void I2cLcd::displayBottomRow | ( | const char * | str | ) |
Display a C-string on the bottom row.
str
the C-string to display. void I2cLcd::displayTopRow | ( | const char * | str | ) |
Display a C-string on the top row.
str
the C-string to display. int I2cLcd::init | ( | ) |
Initialize the I2cLcd object. This must be called before using the I2cLcd, or calling any of the other member functions. The I2C system must be initialized before calling this function (by calling I2cMaster::start() from I2cMaster.h).
The LCD display is initialized in 16-column, 2-row mode.
|
inherited |
Print a null-terminated string to the output stream, with or without adding a new line character at the end.
str
is the null-terminated string to output. addLn
if true, a new line character is added at the end of the output; the default is false.
|
inherited |
Print a number of bytes to the output stream, with or without adding a new line character at the end.
buf
is the buffer containing bytes to output. size
is the number of bytes from the buffer to output. addLn
if true, a new line character is added at the end of the output; the default is false.
|
inherited |
Print a single character to the output stream, with or without adding a new line character at the end.
c
is the character to output. addLn
if true, a new line character is added at the end of the output; the default is false.
|
inherited |
Print an 8-bit integer to the output stream, with or without adding a new line character at the end.
n
is the integer to output. base
is the base used to represent the number; should be one of IntegerOutputBase; defaults to decimal representation (kDec). addLn
if true, a new line character is added at the end of the output; the default is false.
|
inlineinherited |
Print an 8-bit unsigned integer to the output stream, with or without adding a new line character at the end.
n
is the integer to output. base
is the base used to represent the number; should be one of IntegerOutputBase; defaults to decimal representation (kDec). addLn
if true, a new line character is added at the end of the output; the default is false.
|
inherited |
Print an integer to the output stream, with or without adding a new line character at the end.
n
is the integer to output. base
is the base used to represent the number; should be one of IntegerOutputBase; defaults to decimal representation (kDec). addLn
if true, a new line character is added at the end of the output; the default is false.
|
inlineinherited |
Print an unsigned integer to the output stream, with or without adding a new line character at the end.
n
is the unsigned integer to output. base
is the base used to represent the number; should be one of IntegerOutputBase; defaults to decimal representation (kDec). addLn
if true, a new line character is added at the end of the output; the default is false.
|
inherited |
Print a long integer to the output stream, with or without adding a new line character at the end.
n
is the long integer to output. base
is the base used to represent the number; should be one of IntegerOutputBase; defaults to decimal representation (kDec). addLn
if true, a new line character is added at the end of the output; the default is false.
|
inherited |
Print an unsigned long integer to the output stream, with or without adding a new line character at the end.
n
is the unsigned long integer to output. base
is the base used to represent the number; should be one of IntegerOutputBase; defaults to decimal representation (kDec). addLn
if true, a new line character is added at the end of the output; the default is false.
|
inherited |
Print a floating point number to the output stream, with or without adding a new line character at the end.
d
is the floating point number to output. digits
is the number of decimal digits to output; the default is 2. addLn
if true, a new line character is added at the end of the output; the default is false.
|
inlineinherited |
Print a null-terminated string to the output stream, adding a new line character at the end.
str
is the null-terminated string to output.
|
inlineinherited |
Print a number of bytes to the output stream, adding a new line character at the end.
buf
is the buffer containing bytes to output. size
is the number of bytes from the buffer to output.
|
inlineinherited |
Print a single character to the output stream, adding a new line character at the end.
c
is the character to output.
|
inlineinherited |
Print an 8-bit integer to the output stream, adding a new line character at the end.
n
is the integer to output. base
is the base used to represent the number; should be one of IntegerOutputBase; defaults to decimal representation (kDec).
|
inlineinherited |
Print an 8-bit unsigned integer to the output stream, adding a new line character at the end.
n
is the unsigned integer to output. base
is the base used to represent the number; should be one of IntegerOutputBase; defaults to decimal representation (kDec).
|
inlineinherited |
Print an integer to the output stream, adding a new line character at the end.
n
is the integer to output. base
is the base used to represent the number; should be one of IntegerOutputBase; defaults to decimal representation (kDec).
|
inlineinherited |
Print an unsigned integer to the output stream, adding a new line character at the end.
n
is the unsigned integer to output. base
is the base used to represent the number; should be one of IntegerOutputBase; defaults to decimal representation (kDec).
|
inlineinherited |
Print a long integer to the output stream, adding a new line character at the end.
n
is the long integer to output. base
is the base used to represent the number; should be one of IntegerOutputBase; defaults to decimal representation (kDec).
|
inlineinherited |
Print an unsigned long integer to the output stream, adding a new line character at the end.
n
is the unsigned long integer to output. base
is the base used to represent the number; should be one of IntegerOutputBase; defaults to decimal representation (kDec).
|
inlineinherited |
Print a floating point number to the output stream, adding a new line character at the end.
d
is the flaoting point number to output. digits
is the number of decimal digits to output; the default is 2.uint8_t I2cLcd::readButtons | ( | ) |
Read the state of the buttons associated with the LCD display.
int I2cLcd::setBacklight | ( | uint8_t | color | ) |
Set the backlight to a given color. Set a black-and-white LCD display to White if you want to have a backlight.
color
the color to set the backlight. Pass one of kBacklight_Red, kBacklight_Yellow, kBacklight_Green, kBacklight_Teal, kBacklight_Blue, kBacklight_Violet, or kBacklight_White. void I2cLcd::setCursor | ( | uint8_t | row, |
uint8_t | col | ||
) |
Move the cursor the a particular row and column.
row
the row to move the cursor to (numbering starts at 0). col
the column to move the cursor to (numbering starts at 0).
|
virtual |
Write a single character to the LCD at the current cursor location. This implements the pure virtual function Writer::write( char c ).
the
character to be written.Implements Writer.
|
virtual |
Write a C-string to the LCD at the current cursor location. This implements the pure virtual function Writer::write( const char* str ).
the
C-string to be written.Implements Writer.
|
virtual |
Write a given number of characters from a buffer to the LCD at the current cursor location. This implements the pure virtual function Writer::write( const char* buffer, size_t size ).
buffer
the buffer of characters to write. size
the number of characters to writeImplements Writer.
|
virtual |
Write a given number of bytes from a buffer to the LCD at the current cursor location. This implements the pure virtual function Writer::write( const uint8_t* buffer, size_t size ).
buffer
the buffer of bytes to write. size
the number of bytes to writeImplements Writer.