ArduinoLibs
|
Enhanced library for Freetronics 16x2 LCD shields. More...
#include <LCD.h>
Public Types | |
enum | ScreenSaverMode { DisplayOff, BacklightOff, BacklightOnSelect } |
Screen saver mode that controls the display and back light. More... | |
Public Member Functions | |
LCD () | |
Initialize the Freetronics LCD display with the default pin assignment. | |
LCD (uint8_t pin9) | |
Initialize the Freetronics LCD display for USBDroid. | |
void | display () |
Turns on the display of text on the LCD and the back light. | |
void | noDisplay () |
Turns off the display of text on the LCD and the back light. | |
ScreenSaverMode | screenSaverMode () const |
Returns the current screen saver mode; default is DisplayOff. | |
void | setScreenSaverMode (ScreenSaverMode mode) |
Sets the current screen saver mode. | |
void | enableScreenSaver (int timeoutSecs=10) |
Enables the screen saver and causes it to activate after timeoutSecs of inactivity on the buttons. | |
void | disableScreenSaver () |
Disables the screen saver. | |
bool | isScreenSaved () const |
Returns true if the screen has been saved; false otherwise. | |
int | getButton () |
Gets the next button press, release, or idle event. |
Enhanced library for Freetronics 16x2 LCD shields.
This class extends the standard Arduino LiquidCrystal library with extra functionality for the Freetronics 16x2 LCD shield:
http://www.freetronics.com/pages/16x2-lcd-shield-quickstart-guide
The Freetronics LCD has an additional back light, which is turned on and off with the display() and noDisplay() functions. The user can also call enableScreenSaver() to cause the display and back light to automatically turn off after a specific timeout. The setScreenSaverMode() function controls which of the display and back light are disabled when the screen saver activates.
The Freetronics LCD also has 5 push buttons for Left, Right, Up, Down, and Select, to assist with the creation of interactive sketches. The user can call getButton() to get the current button state. One of the following values may be returned:
For convenience, all RELEASED button codes are the negation of their pressed counterparts. That is, LCD_BUTTON_LEFT_RELEASED == -LCD_BUTTON_LEFT. LCD_BUTTON_NONE is defined to be zero. Thus, you can check if a generic button has been pressed with button > 0
and if a generic button has been released with button < 0
.
See the Hello World example for more information on using the LCD class.
enum LCD::ScreenSaverMode |
Screen saver mode that controls the display and back light.
LCD::LCD | ( | ) | [inline] |
LCD::LCD | ( | uint8_t | pin9 | ) | [inline] |
Initialize the Freetronics LCD display for USBDroid.
On the USBDroid, the D9 pin is used for USB Host functionality. Either the USB Host's use of D9 must be reassigned to another pin, or the Freetronics LCD shield must be modified. The following Web page describes the modifications that are necessary: http://www.freetronics.com/pages/combining-the-lcd-keypad-shield-and-the-usbdroid
If you choose to modify the LCD shield, then you must use this version of the constructor to initialize the shield, passing the alternative pin as the pin9 parameter. Using the recommended pin from the above Web page of A1, you would initialize the LCD as follows:
LCD lcd(A1);
void LCD::disableScreenSaver | ( | ) |
Disables the screen saver.
void LCD::display | ( | ) |
Turns on the display of text on the LCD and the back light.
If the screen saver is active, then calling this function will deactivate the screen saver and reset the timeout. Thus, this function can be called for force the screen to restore.
void LCD::enableScreenSaver | ( | int | timeoutSecs = 10 | ) |
Enables the screen saver and causes it to activate after timeoutSecs of inactivity on the buttons.
If timeoutSecs is less than or equal to zero, then the call is equivalent to calling disableScreenSaver().
For the screen saver to work, the application must regularly call getButton() to fetch the LCD's button state even if no buttons are pressed.
If the timeoutSecs parameter is not supplied, the default is 10 seconds.
int LCD::getButton | ( | ) |
Gets the next button press, release, or idle event.
If no buttons are pressed, this function will return LCD_BUTTON_NONE.
When a button is pressed, this function will return one of LCD_BUTTON_LEFT, LCD_BUTTON_RIGHT, LCD_BUTTON_UP, LCD_BUTTON_DOWN, or LCD_BUTTON_SELECT. While the button is pressed, this function will return LCD_BUTTON_NONE until the button is released. When the button is released, this function will return one of LCD_BUTTON_LEFT_RELEASED, LCD_BUTTON_RIGHT_RELEASED, LCD_BUTTON_UP_RELEAED, LCD_BUTTON_DOWN_RELEASED, or LCD_BUTTON_SELECT_RELEASED.
If the screen saver is currently active, then it will be deactivated by this function whenever a button is pressed. If screenSaverMode() is DisplayOff, the function will "eat" the button press and return LCD_BUTTON_NONE. The scrren saver can also be deactivated under program control by calling display().
This function debounces the button state automatically so there is no need for the caller to worry about spurious button events.
bool LCD::isScreenSaved | ( | ) | const [inline] |
Returns true if the screen has been saved; false otherwise.
void LCD::noDisplay | ( | ) |
Turns off the display of text on the LCD and the back light.
This function can be called to force the screen saver to activate.
ScreenSaverMode LCD::screenSaverMode | ( | ) | const [inline] |
Returns the current screen saver mode; default is DisplayOff.
void LCD::setScreenSaverMode | ( | ScreenSaverMode | mode | ) |
Sets the current screen saver mode.