-
Notifications
You must be signed in to change notification settings - Fork 1
/
FullDemo_RS232.ino
204 lines (169 loc) · 4.87 KB
/
FullDemo_RS232.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
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
// OVERVIEW //////////////////////////////////////
// LiquidCrystal NKC: Library for Arduino
// Full Arduino IDE Demonstration Sketch
// Sketch v21.316 by Dominic M. Luciano
//
// This sketch is intended to highlight & display
// the major functions of the LiquidCrystal NKC
// library and their potential uses and usages in
// conjunction with an NKC Electronics Serial LCD
// display module running in RS232 mode
//////////////////////////////////////////////////
// CONNECTIONS ///////////////////////////////////
// LCD PIN 1 [RXD] -> ARDUINO UNO PIN D1 [TXD]
// LCD PIN 2 [VSS] -> ARDUINO UNO GND
// LCD PIN 3 [VDD] -> ARDUINO UNO +5V
//////////////////////////////////////////////////
#include <Wire.h>
#include <LiquidCrystal_NKC.h>
// DECLARATIONS //////////////////////////////////
// Constructor & Parameters //
// Interface, Baud Rate, Columns, Rowa
LC_NKC lcd(RS232, 9600, 20, 4);
// General Variables //
// Strings We'll Use Shortly
String ChangingToday = "Changing Today";
String EvolvingTomorrow = "Evolving Tomorrow";
// Custom Character Arrays //
byte heart[8] = {
0b00000,
0b01010,
0b11111,
0b11111,
0b11111,
0b01110,
0b00100,
0b00000
};
void setup() {
// Initialize LCD Module
lcd.begin();
// Turn On LCD Backlight
lcd.backlight();
// Or Use: lcd.setBacklight(HIGH);
// Create New Character From Earlier Byte Array
// We'll Use This Later On...
lcd.createChar(0, heart);
}
void loop() {
// Set Cursor to "Col 0, Row 0" (1st Col, 1st Row)
lcd.home(); // Or Use: lcd.setCursor(0, 0);
// Clear The Entire LCD
lcd.clear();
// Set Cursor to "Col 4, Row 1" (5th Col, 2nd Row)
lcd.setCursor(4, 1);
// Print "Hello, World" to the LCD
lcd.print("Hello, World");
delay(2000);
// Clear LCD From Cols 4 to 16 on Row 1 (5th-17th Column, 2nd Row)
lcd.clear(4, 16, 1);
delay(250);
// Display the LCD Firmware's Version
lcd.displayVersion();
delay(2000);
// Clear The Entire LCD
lcd.clear();
delay(250);
// Display the LCD's Current I2C Address
lcd.displayI2CAddress();
delay(2000);
// Clear Entire LCD
lcd.clear();
delay(250);
// Set Cursor Back to "0, 0"
lcd.home();
// Print Some Text...
lcd.print("LiquidCrystal NKC");
// Set Cursor To "Col 0, Row 1" (1st Col, 2nd Row)
lcd.setCursor(0, 1);
lcd.print("By Dominic Luciano");
delay(2000);
// Set Cursor To "Col 0, Row 2" (1st Col, 3rd Row)
lcd.setCursor(0, 2);
lcd.print("github.com/DomiLuci");
delay(2000);
// Set Cursor To "0, 2"
lcd.setCursor(0, 3);
//Turn LCD Blinking Cursor On
lcd.blink();
// or use: lcd.blinkOn();
// or use: lcd.blink(true);
// And For My Next Trick...
// Making Text Appear Behind A Blinking Cursor
for (byte i = 0; i <= 18; i++) {
// Print Each Letter of the String At Index "i"
lcd.print(String(ChangingToday.charAt(i)));
// Cursor Must Be Reset After Each Letter to Col "i"
lcd.setCursor(i, 3);
// Move the Blinking Cursor One Spot Right Every 100ms
lcd.right();
delay(100);
}
delay(1000);
// Making Text Appear Behind A Blinking Cursor
// ...In Reverse
for (byte i = 19; i <= 19; i--) {
// Print Each Letter of the String At Index "i"
lcd.print(String(EvolvingTomorrow.charAt(i)));
// Cursor Must Be Reset After Each Letter to Col "i"
lcd.setCursor(i, 3);
// Move the Blinking Cursor One Spot Left Every 100ms
lcd.left();
delay(100);
}
//Turn LCD Blinking Cursor Off
lcd.noBlink();
// Or Use: lcd.blinkOff();
// Or Use: lcd.blink(false);
delay(2000);
// Drop the Contrast to "0"
lcd.setContrast(0);
// Clear Rows 0, 1, 2, and 3 (1st, 2nd, 3rd, and 4th Row)
lcd.clear(0);
lcd.clear(1);
lcd.clear(2);
lcd.clear(3);
// Reset Cursor to "0, 3"
lcd.setCursor(2, 1);
// Print "Now Let's Scroll"
lcd.print("Now Let's Scroll");
// Fade The Contrast Back In To 200...
for (byte i = 0; i <= 200; i++) {
// Set Contrast to "i"
lcd.setContrast(i);
delay(15);
}
delay(2000);
// Set Cursor to "20, 1" (21st Column of 2nd Row, Sort Of)
lcd.setCursor(20, 1);
// Shift ALL Text Left 2 Positions, Once Every 100ms...
// The Easy Way This Time
lcd.scrollDisplayLeft(1, 100);
// Or Use: lcd.shiftLeft(14, 100);
delay(250);
byte col = 21; // Variable For Next Loop
// Now Shift ALL Text Right 20 Positions, Once Every 100ms...
// The Harder Way
for (byte i = 0; i <= 20; i++) {
delay(100);
lcd.scrollDisplayRight();
// Or Use: shiftRight();
// Clear Each Character Before It Re-enters Frame
lcd.clear(col, 1);
col--;
}
delay(2000);
// Clear The Entire LCD...
// Also Resetting The LCD Shift
lcd.clear();
// Set Cursor to "3, 1" (4th Column, 2nd Row)
lcd.setCursor(3, 1);
// Print Some Thank You Text
lcd.print("Thanks 4 The ");
// Show That Heart We Made Earlier
lcd.write((byte)0);
delay(2000);
//Clean Up The Entire LCD Before Loop Reset
lcd.clear();
delay(1500);
}