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
138 _backlightPin = LCD_BACK_LIGHT;
139 backlightInit =
false;
142 pinMode(LCD_BUTTON_PIN, INPUT);
143 digitalWrite(LCD_BUTTON_PIN, LOW);
144 prevButton = LCD_BUTTON_NONE;
145 debounceButton = LCD_BUTTON_NONE;
151 lastRestore = millis();
184 if (_backlightPin != pin) {
187 pinMode(_backlightPin, INPUT);
188 digitalWrite(_backlightPin, LOW);
191 backlightInit =
false;
209 pinMode(_backlightPin, OUTPUT);
210 digitalWrite(_backlightPin, HIGH);
212 backlightInit =
true;
213 lastRestore = millis();
227 pinMode(_backlightPin, OUTPUT);
228 digitalWrite(_backlightPin, LOW);
230 backlightInit =
true;
270 if (this->mode != mode) {
299 timeout = ((
unsigned long)timeoutSecs) * 1000;
322 static unsigned char const buttonMappings[] PROGMEM = {
323 2, 0, 0, 0, 3, 0, 0, 0, 0, 4, 4, 0, 0, 0, 0, 1,
324 1, 0, 0, 0, 0, 0, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0
326 #define mapButton(value) (pgm_read_byte(&(buttonMappings[(value) >> 5])))
360 int button = mapButton(analogRead(LCD_BUTTON_PIN));
363 unsigned long currentTime = millis();
364 if (button != debounceButton)
365 lastDebounce = currentTime;
366 debounceButton = button;
367 if ((currentTime - lastDebounce) < DEBOUNCE_DELAY)
371 if (prevButton == LCD_BUTTON_NONE && button != LCD_BUTTON_NONE) {
377 if (button == LCD_BUTTON_SELECT) {
378 pinMode(_backlightPin, OUTPUT);
379 digitalWrite(_backlightPin, HIGH);
381 backlightInit =
true;
386 return LCD_BUTTON_NONE;
395 lastRestore = currentTime;
397 }
else if (prevButton != LCD_BUTTON_NONE && button == LCD_BUTTON_NONE) {
398 button = -prevButton;
399 prevButton = LCD_BUTTON_NONE;
400 lastRestore = currentTime;
403 return LCD_BUTTON_NONE;
407 if (!screenSaved && prevButton == LCD_BUTTON_NONE &&
408 timeout != 0 && (currentTime - lastRestore) >= timeout)
410 return LCD_BUTTON_NONE;