-
Notifications
You must be signed in to change notification settings - Fork 10
/
LcdDisplayApp.java
157 lines (131 loc) · 4.69 KB
/
LcdDisplayApp.java
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package com.pi4j.crowpi.applications;
import com.pi4j.context.Context;
import com.pi4j.crowpi.Application;
import com.pi4j.crowpi.components.LcdDisplayComponent;
/**
* Example Application of using the Crow Pi LCD Display
*/
public class LcdDisplayApp implements Application {
@Override
public void execute(Context pi4j) {
LcdDisplayComponent lcd = new LcdDisplayComponent(pi4j);
System.out.println("Here we go.. let's have some fun with that LCD Display!");
// First we need to setup the LCD Display. That for just call initialize
lcd.initialize();
// Write text to the lines separate
lcd.writeLine("Hello", 1);
lcd.writeLine(" World!", 2);
// Wait a little to have some time to read it
sleep(3000);
// Clear the display to start next parts
lcd.clearDisplay();
// Let's try to draw a house. To keep this method short and clean we create the characters in a separate
// method below.
createCharacters(lcd);
// Now all characters are ready. Just draw them on the right place by moving the cursor and writing the
// created characters to specific positions
lcd.writeCharacter('\1', 1, 1);
lcd.writeCharacter('\2', 2, 1);
lcd.writeCharacter('\3', 1, 2);
lcd.writeCharacter('\4', 2, 2);
// Delay a few seconds to let you enjoy our little house
sleep(3000);
// Uhm but the view from our house would be better from the other side. lets move it over there
for (int i = 0; i < 10; i++) {
lcd.moveDisplayRight();
sleep(100);
}
// Enjoy the new view from our house
sleep(5000);
// To clean up or start with something new just use the clearDisplay method
lcd.clearDisplay();
// To write some text there are different methods. The simplest one is this one which automatically inserts
// linebreaks if needed.
lcd.writeText("Boohoo that's so simple to use!");
// Delay again
sleep(3000);
// Of course it is also possible to write a single line
lcd.writeLine("hard to usE!", 2);
sleep(3000);
// The display always works with a current position. That's called the cursor. You can simply modify the
// cursor with a few method calls
lcd.setCursorVisibility(true);
lcd.setCursorBlinking(true);
// Now you can see the cursor is right behind the last character we wrote before.
sleep(5000);
// The last text had a mistake so let's move there and fix it.
lcd.moveCursorLeft();
lcd.moveCursorLeft();
lcd.moveCursorLeft();
sleep(1000);
// Oops moved too far, lets move one to the right
lcd.moveCursorRight();
// And fix it
lcd.writeCharacter('e');
// Now it looks fine
sleep(3000);
// Cursor annoying? Simply turn it off and clear the display again
lcd.setCursorBlinking(false);
lcd.setCursorVisibility(false);
lcd.clearDisplay();
// Some more text writings
lcd.writeText("Want more fun?");
sleep(3000);
// Its also possible to just clear a single line
lcd.clearLine(2);
// Write on the previously cleared line
lcd.writeLine("No, thanks.", 2);
sleep(3000);
// A \n makes a manual line break
lcd.writeText("Okay ...\nBye Bye! :-(");
sleep(5000);
// Turn off the backlight makes the display appear turned off
lcd.setDisplayBacklight(false);
}
public void createCharacters(LcdDisplayComponent lcd) {
// Create upper left part of the house
lcd.createCharacter(1, new byte[]{
0b00000,
0b00000,
0b00000,
0b00001,
0b00011,
0b00111,
0b01111,
0b11111
});
// Create upper right part of the house
lcd.createCharacter(2, new byte[]{
0b00000,
0b00000,
0b00010,
0b10010,
0b11010,
0b11110,
0b11110,
0b11111
});
// Create lower left part of the house
lcd.createCharacter(3, new byte[]{
0b11111,
0b11111,
0b11111,
0b11111,
0b10001,
0b10001,
0b10001,
0b10001
});
// Create lower right part of the house
lcd.createCharacter(4, new byte[]{
0b11111,
0b11111,
0b11111,
0b10001,
0b10001,
0b10001,
0b11111,
0b11111
});
}
}