-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathLCDKeypad.h
80 lines (58 loc) · 2.24 KB
/
LCDKeypad.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
LCDKeypad Arduino library
https://github.com/dzindra/LCDKeypad
Copyright 2014 Jindřich Doležy (jindrich@dolezy.cz)
based on the code by fj604 from http://forum.arduino.cc/index.php?topic=38061.0
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#ifndef LCDKeypad_h
#define LCDKeypad_h
#include <inttypes.h>
#include <LiquidCrystal.h>
#define KEYPAD_NONE 0
#define KEYPAD_RIGHT 1
#define KEYPAD_UP 2
#define KEYPAD_DOWN 3
#define KEYPAD_LEFT 4
#define KEYPAD_SELECT 5
#define KEYPAD_BLOCKED 255
#define KEYPAD_BUTTON_ANALOG_PIN 0
#define KEYPAD_BACKLIGHT_PIN 10
#define KEYPAD_LCD_PINS 8, 9, 4, 5, 6, 7
// you can change tresholds for detecting key presses
#define KEYPAD_TRESHOLD_NONE 1000
#define KEYPAD_TRESHOLD_RIGHT 50
#define KEYPAD_TRESHOLD_DOWN 380
#define KEYPAD_TRESHOLD_UP 195
#define KEYPAD_TRESHOLD_LEFT 555
#define KEYPAD_TRESHOLD_SELECT 790
class LCDKeypad : public LiquidCrystal
{
public:
LCDKeypad();
LCDKeypad(uint8_t bl_pin, uint8_t button_apin);
void keypadInit(uint8_t bl_pin, uint8_t button_apin);
uint8_t button();
// use this method for menus and other things where repeated and filtered keypresses are needed
uint8_t buttonBlocking(uint16_t block_delay = 500, uint16_t repeat_delay = 300);
// some lcd boards have issue with backlight frying output pins
// see http://forum.arduino.cc//index.php?topic=96747 for discussion and solutions
// this code uses universal solution with pin input/output toggling, so it should be
// safe on all types of this board
void backlight();
void noBacklight();
private:
uint8_t _bl_pin;
uint8_t _button_pin;
uint32_t _block_time;
uint8_t _last_button;
};
#endif