| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

LCDKeypad.cpp
Go to the documentation of this file.
1 /*
2 LCDKeypad.cpp
3 */
4
5
6
7 #include <Arduino.h>
8 #include <LiquidCrystal.h>
9 #include "LCDKeypad.h"
10
11 /** \brief degree sign for LCD see https://omerk.github.io/lcdchargen/ */
12 uint8_t LCDKeypad::degree[8] =
13 {
14 B01100,
15 B10010,
16 B10010,
17 B01100,
18 B00000,
19 B00000,
20 B00000,
21 B00000
22 };
23
24 //template <typename T> inline void LCDKeypad::PRINTSCREEN(T const& A)
25 //{
26 // if (foundLCD) this->print(A);
27 // if (EnableSerialOutput)
28 // Serial.print(A);
29 //}
30
31 /** \fn void searchForLCD()
32 \brief LCD keypad shield detection
33 poor man's way to detect LCD keypad shield:
34 Linduino's pin 10 is connected to the base of a NPN
35 on the LCD keypad. In normal operation this pin must
36 only be driven low or kept tristate to turn the LCD
37 backlight off or on.
38 to detect the base of the NPN we drive the pin high
39 and read back its value. After the read the pin will be
40 set tristate. The driving high phase will last only
41 a few microseconds, during that time the pin will be
42 forced < 0.8 V bei the PN-diode of the transistor.
43 As MCU's max. low level is 1.5V (for 5V supply) the
44 pin will be read as zero, which tells us the LCD is
45 connected.
46 */
47 void LCDKeypad::searchForLCD()
48 {
49 digitalWrite(10, HIGH);
50 pinMode(10, OUTPUT);
51 // pin 10 is connected to PN diode of transistor Q1 on LCD keypad
52 // so it will be forced < 0.8V, max. low level is 1.5V
53 foundLCD = (digitalRead(10) == 0);
54 pinMode(10, INPUT); // go back to tristate
55 digitalWrite(10, LOW);
56 if (foundLCD)
57 {
58 createChar(0, degree);
59 begin(16, 2);
60 }
61 }
62
63 void LCDKeypad::Disable4BitLCD()
64 {
65 foundLCD = false;
66 // disable all drivers
67 pinMode(_ledCtrlPin, INPUT);
68
69 pinMode(8, INPUT);
70 pinMode(9, INPUT);
71
72 pinMode(4, INPUT);
73 pinMode(5, INPUT);
74 pinMode(6, INPUT);
75 pinMode(7, INPUT);
76 }
77
78 LCDKeypad::LCDKeypad(uint8_t ledCtrlPin) : LiquidCrystal(8, 9, 4, 5, 6, 7)
79 {
80 foundLCD = false;
81 _ledCtrlPin = ledCtrlPin;
82 // output PIN state of LED control pin must always be low
83 // this is due to poor design of LCD Keypad shield where arduino's pin 10
84 // is directly connected to the base of a transistor: enabling the pins output
85 // driver and setting the output level to high would draw a big current out
86 // of the pin. thus unfortunately it is even not possible to dimm led
87 // backlight via PWM signal!
88 digitalWrite(_ledCtrlPin, LOW);
89 pinMode(_ledCtrlPin, INPUT); // set pinMode to INPUT to enable LED
90 }
91
92 int LCDKeypad::button()
93 {
94 static int NUM_KEYS = 5;
95 static int adc_key_val[5] = { 30, 150, 360, 535, 760 };
96 int k, input;
97
98 input = analogRead(0);
99
100 for (k = 0; k < NUM_KEYS; k++)
101 if (input < adc_key_val[k])
102 return k;
103
104 return -1; // No valid key pressed
105 }
106
107 void LCDKeypad::LEDon()
108 {
109 digitalWrite(_ledCtrlPin, LOW);
110 pinMode(_ledCtrlPin, INPUT); // set pinMode to INPUT to enable LED
111 }
112
113 void LCDKeypad::LEDoff()
114 {
115 digitalWrite(_ledCtrlPin, LOW);
116 pinMode(_ledCtrlPin, OUTPUT); // set pinMode to OUTPUT to disable LED
117 }
118
119
LCDKeypad::button
int button()
Definition: LCDKeypad.cpp:92
LCDKeypad::degree
static uint8_t degree[8]
degree sign for LCD see https://omerk.github.io/lcdchargen/
Definition: LCDKeypad.h:60
input
#define input(pin)
Return the state of pin "pin".
Definition: Linduino.h:79
LCDKeypad::foundLCD
boolean foundLCD
Definition: LCDKeypad.h:62
LCDKeypad::LEDoff
void LEDoff()
Definition: LCDKeypad.cpp:113
LCDKeypad.h
LCDKeypad::LEDon
void LEDon()
Definition: LCDKeypad.cpp:107
LCDKeypad::LCDKeypad
LCDKeypad(uint8_t ledCtrlPin)
Definition: LCDKeypad.cpp:78
LCDKeypad::Disable4BitLCD
void Disable4BitLCD()
Definition: LCDKeypad.cpp:63
LCDKeypad::searchForLCD
void searchForLCD()
Definition: LCDKeypad.cpp:47