24 #include <avr/pgmspace.h>
25 #if defined(ARDUINO) && ARDUINO >= 100
31 #define LCD_BACK_LIGHT 3 // Default LCD backlight is on D3
32 #define LCD_BUTTON_PIN A0 // Button state is on A0
34 #define DEBOUNCE_DELAY 10 // Delay in ms to debounce buttons
153 _backlightPin = LCD_BACK_LIGHT;
154 backlightInit =
false;
157 pinMode(LCD_BUTTON_PIN, INPUT);
158 digitalWrite(LCD_BUTTON_PIN, LOW);
159 prevButton = LCD_BUTTON_NONE;
160 debounceButton = LCD_BUTTON_NONE;
166 lastRestore = millis();
199 if (_backlightPin != pin) {
202 pinMode(_backlightPin, INPUT);
203 digitalWrite(_backlightPin, LOW);
206 backlightInit =
false;
223 LiquidCrystal::display();
224 pinMode(_backlightPin, OUTPUT);
225 digitalWrite(_backlightPin, HIGH);
227 backlightInit =
true;
228 lastRestore = millis();
241 LiquidCrystal::noDisplay();
242 pinMode(_backlightPin, OUTPUT);
243 digitalWrite(_backlightPin, LOW);
245 backlightInit =
true;
285 if (this->mode != mode) {
314 timeout = ((
unsigned long)timeoutSecs) * 1000;
337 static unsigned char const buttonMappings[] PROGMEM = {
338 2, 0, 0, 0, 3, 0, 0, 0, 0, 4, 4, 0, 0, 0, 0, 1,
339 1, 0, 0, 0, 0, 0, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0
341 #define mapButton(value) (pgm_read_byte(&(buttonMappings[(value) >> 5])))
375 int button = mapButton(analogRead(LCD_BUTTON_PIN));
378 unsigned long currentTime = millis();
379 if (button != debounceButton)
380 lastDebounce = currentTime;
381 debounceButton = button;
382 if ((currentTime - lastDebounce) < DEBOUNCE_DELAY)
386 if (prevButton == LCD_BUTTON_NONE && button != LCD_BUTTON_NONE) {
392 if (button == LCD_BUTTON_SELECT) {
393 pinMode(_backlightPin, OUTPUT);
394 digitalWrite(_backlightPin, HIGH);
396 backlightInit =
true;
401 return LCD_BUTTON_NONE;
410 lastRestore = currentTime;
412 }
else if (prevButton != LCD_BUTTON_NONE && button == LCD_BUTTON_NONE) {
413 button = -prevButton;
414 prevButton = LCD_BUTTON_NONE;
415 lastRestore = currentTime;
418 return LCD_BUTTON_NONE;
422 if (!screenSaved && prevButton == LCD_BUTTON_NONE &&
423 timeout != 0 && (currentTime - lastRestore) >= timeout)
425 return LCD_BUTTON_NONE;
void setScreenSaverMode(ScreenSaverMode mode)
Sets the current screen saver mode.
int getButton()
Gets the next button press, release, or idle event.
Same as BacklightOff but the screen saver is only deactivated when Select is pressed; other buttons h...
ScreenSaverMode
Screen saver mode that controls the display and back light.
void setBacklightPin(uint8_t pin)
Sets the back light pin for the LCD shield.
void enableScreenSaver(int timeoutSecs=10)
Enables the screen saver and causes it to activate after timeoutSecs of inactivity on the buttons...
void noDisplay()
Turns off the display of text on the LCD and the back light.
Turn off both the display and the backlight when the screen saver is activated.
void disableScreenSaver()
Disables the screen saver.
void display()
Turns on the display of text on the LCD and the back light.