ArduinoLibs
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
LCD.h
1 /*
2  * Copyright (C) 2012 Southern Storm Software, Pty Ltd.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included
12  * in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20  * DEALINGS IN THE SOFTWARE.
21  */
22 
23 #ifndef LCD_h
24 #define LCD_h
25 
26 // Extended version of the LiquidCrystal library that works specifically
27 // with Freetronics' 16x2 LCD display, including support for the back
28 // light and the Up/Down/Left/Right/Select buttons. More info:
29 //
30 // http://www.freetronics.com/pages/16x2-lcd-shield-quickstart-guide
31 
32 // Include a copy of the standard LiquidCrystal library so we can extend it.
33 #include "utility/LiquidCrystal.h"
34 
35 // Button event codes.
36 #define LCD_BUTTON_NONE 0
37 #define LCD_BUTTON_LEFT 1
38 #define LCD_BUTTON_RIGHT 2
39 #define LCD_BUTTON_UP 3
40 #define LCD_BUTTON_DOWN 4
41 #define LCD_BUTTON_SELECT 5
42 #define LCD_BUTTON_LEFT_RELEASED -1
43 #define LCD_BUTTON_RIGHT_RELEASED -2
44 #define LCD_BUTTON_UP_RELEASED -3
45 #define LCD_BUTTON_DOWN_RELEASED -4
46 #define LCD_BUTTON_SELECT_RELEASED -5
47 
48 class LCD : public LiquidCrystal {
49 public:
50  LCD() : LiquidCrystal(8, 9, 4, 5, 6, 7) { init(); }
51  LCD(uint8_t pin9) : LiquidCrystal(8, pin9, 4, 5, 6, 7) { init(); }
52  LCD(uint8_t rs, uint8_t enable,
53  uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3)
54  : LiquidCrystal(rs, enable, d0, d1, d2, d3) { init(); }
55 
56  uint8_t backlightPin() const { return _backlightPin; }
57  void setBacklightPin(uint8_t pin);
58 
59  void display();
60  void noDisplay();
61 
63  {
67  };
68 
69  ScreenSaverMode screenSaverMode() const { return mode; }
71 
72  void enableScreenSaver(int timeoutSecs = 10);
73  void disableScreenSaver();
74  bool isScreenSaved() const { return screenSaved; }
75 
76  int getButton();
77 
78 private:
79  uint8_t _backlightPin;
80  bool backlightInit;
81  int prevButton;
82  int debounceButton;
83  unsigned long timeout;
84  unsigned long lastRestore;
85  unsigned long lastDebounce;
86  bool screenSaved;
87  bool eatRelease;
88  ScreenSaverMode mode;
89 
90  void init();
91 };
92 
93 #endif
void setScreenSaverMode(ScreenSaverMode mode)
Sets the current screen saver mode.
Definition: LCD.cpp:283
int getButton()
Gets the next button press, release, or idle event.
Definition: LCD.cpp:368
Same as BacklightOff but the screen saver is only deactivated when Select is pressed; other buttons h...
Definition: LCD.h:66
ScreenSaverMode
Screen saver mode that controls the display and back light.
Definition: LCD.h:62
LCD(uint8_t rs, uint8_t enable, uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3)
Initialize the Freetronics LCD display with custom pins.
Definition: LCD.h:52
Turn off the back light but leave the display on when the screen saver is activated.
Definition: LCD.h:65
void setBacklightPin(uint8_t pin)
Sets the back light pin for the LCD shield.
Definition: LCD.cpp:197
LCD()
Initialize the Freetronics LCD display with the default pin assignment.
Definition: LCD.h:50
void enableScreenSaver(int timeoutSecs=10)
Enables the screen saver and causes it to activate after timeoutSecs of inactivity on the buttons...
Definition: LCD.cpp:309
LCD(uint8_t pin9)
Initialize the Freetronics LCD display for USBDroid.
Definition: LCD.h:51
void noDisplay()
Turns off the display of text on the LCD and the back light.
Definition: LCD.cpp:238
Turn off both the display and the backlight when the screen saver is activated.
Definition: LCD.h:64
void disableScreenSaver()
Disables the screen saver.
Definition: LCD.cpp:323
void display()
Turns on the display of text on the LCD and the back light.
Definition: LCD.cpp:221
uint8_t backlightPin() const
Returns the pin that is being used to control the back light. The default is 3.
Definition: LCD.h:56
Enhanced library for Freetronics 16x2 LCD shields.
Definition: LCD.h:48
bool isScreenSaved() const
Returns true if the screen has been saved; false otherwise.
Definition: LCD.h:74
ScreenSaverMode screenSaverMode() const
Returns the current screen saver mode; default is DisplayOff.
Definition: LCD.h:69