/
LcdHelloWorld.ino
75 lines (64 loc) · 1.94 KB
/
LcdHelloWorld.ino
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
/*
Sample code made for the LCD Keypad Arduino Shield
*/
// include the library code:
#include <LiquidCrystal.h>
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
// Pins used by the shield
const int rs = 8, en = 9, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
int keypad_in;
int keypad_old = 9999;
bool button_pressed = false;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
// Quiick utility function for clearing just a single line of the LCD
void clearLine(int lineNo) {
lcd.setCursor(0, lineNo);
lcd.print(" ");
lcd.setCursor(0, lineNo);
}
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("TipsyBrew");
lcd.setCursor(0, 1);
lcd.print("and so it begins");
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
keypad_in = analogRead(0);
// The value of keypad_in can jump around a point, so I put in a 10 point buffer
button_pressed = (abs(keypad_in - keypad_old) > 10) ? true : false;
// My approximate values, I assume it may vary
// No buttons pressed = 1023
// Select = 725
// Left = 483
// Up = 131
// Down = 308
// Right = 0
if (button_pressed) {
keypad_old = keypad_in;
clearLine(1);
lcd.print("A0: ");
lcd.print(keypad_in);
// I kept the above output defaulted because it is handier for determining your key values, however if want prettier output, use the code below
/*
if (keypad_in > 875) {
lcd.print("None");
} else if (keypad_in > 600) {
lcd.print("Select Pressed");
} else if (keypad_in > 400) {
lcd.print("Left Pressed");
} else if (keypad_in > 200) {
lcd.print("Down Pressed");
} else if (keypad_in > 75) {
lcd.print("Up Pressed");
} else {
lcd.print("Right Pressed");
}
*/
}
}