Erriez LCD Keypad Shield library for Arduino  1.1.0
This is a LCD Keypad Shield library for Arduino
ErriezLCDKeypadShield.cpp
Go to the documentation of this file.
1 /*
2  * MIT License
3  *
4  * Copyright (c) 2018-2020 Erriez
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
33 #if (defined(__AVR__))
34 #include <avr/pgmspace.h>
35 #else
36 #include <pgmspace.h>
37 #endif
38 
39 #include "ErriezLCDKeypadShield.h"
40 
48  LiquidCrystal(LCD_PIN_RS, LCD_PIN_EN,
50 {
51  // Initialize backlight pin
52  pinMode(LCD_BACK_LIGHT_PIN, OUTPUT);
53 
54  // Turn backlight on
55  backlightOn();
56 
57  // Initialize LCD
58  begin(16, 2);
59  setCursor(0, 0);
60 }
61 
67 {
68  static LCDButton keyLast = ButtonNone;
69  static unsigned long keyTimeLast = 0;
70  int analogKey;
71  LCDButton key;
72 
73  analogKey = analogRead(0);
74 
75  if ((millis() - keyTimeLast) < 100) {
76  return keyLast;
77  }
78 
79  keyTimeLast = millis();
80 
81  if (analogKey < 50) {
82  key = ButtonRight;
83  } else if (analogKey < 200) {
84  key = ButtonUp;
85  } else if (analogKey < 300) {
86  key = ButtonDown;
87  } else if (analogKey < 500) {
88  key = ButtonLeft;
89  } else if (analogKey < 700) {
90  key = ButtonSelect;
91  } else {
92  key = ButtonNone;
93  }
94 
95  if (key == keyLast) {
96  return key;
97  } else {
98  keyLast = key;
99  return ButtonNone;
100  }
101 }
102 
107 {
108  digitalWrite(LCD_BACK_LIGHT_PIN, HIGH);
109 }
110 
115 {
116  digitalWrite(LCD_BACK_LIGHT_PIN, LOW);
117 }
void backlightOff()
Turn backlight LED off.
#define LCD_PIN_RS
LCD RS pin.
LCDButton
LCD buttons.
LCD Keypad Shield library for Arduino.
#define LCD_PIN_EN
LCD EN pin.
#define LCD_BACK_LIGHT_PIN
LCD backlight pin.
#define LCD_PIN_D2
LCD D2 pin.
#define LCD_PIN_D1
LCD D1 pin.
#define LCD_PIN_D3
LCD D3 pin.
LCDButton getButtons()
Read buttons from one analog pin.
#define LCD_PIN_D0
LCD D0 pin.
LCDKeypadShield()
Constructor LCDKeypadShield class.
void backlightOn()
Turn backlight LED on.