ArduinoLibs
 All Classes Files Functions Variables Typedefs Enumerations Enumerator 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 
53  uint8_t backlightPin() const { return _backlightPin; }
54  void setBacklightPin(uint8_t pin);
55 
56  void display();
57  void noDisplay();
58 
60  {
64  };
65 
66  ScreenSaverMode screenSaverMode() const { return mode; }
68 
69  void enableScreenSaver(int timeoutSecs = 10);
70  void disableScreenSaver();
71  bool isScreenSaved() const { return screenSaved; }
72 
73  int getButton();
74 
75 private:
76  uint8_t _backlightPin;
77  bool backlightInit;
78  int prevButton;
79  int debounceButton;
80  unsigned long timeout;
81  unsigned long lastRestore;
82  unsigned long lastDebounce;
83  bool screenSaved;
84  bool eatRelease;
85  ScreenSaverMode mode;
86 
87  void init();
88 };
89 
90 #endif