-
Notifications
You must be signed in to change notification settings - Fork 0
/
lcd_functions.cpp
206 lines (195 loc) · 4.02 KB
/
lcd_functions.cpp
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
205
206
#include "HardwareSerial.h"
#include "lcd_functions.h"
#include "customChars.h"
#define introDelay 6500 // The delay between the intro sequence and the Initial wifi connection
bool lcd2004 = false; // If you are using a 16x2, set this to false.
LiquidCrystal_I2C lcd(0x27, 16, 2);
void initLCD(){
if(lcd2004){
lcd = LiquidCrystal_I2C(0x27, 20, 4);
Serial.println("LCD Setting = 20x4.");
}
else{
lcd = LiquidCrystal_I2C(0x27, 16, 2);
Serial.println("LCD Setting = 16x2.");
}
}
void createCustomChars(){
lcd.createChar(0, loadingOne);
lcd.createChar(1, loadingTwo);
lcd.createChar(2, check);
lcd.createChar(3, upArrow);
lcd.createChar(4, downArrow);
lcd.createChar(5, funkyChar);
lcd.createChar(6, newDollar);
lcd.createChar(7, borderTB);
}
void displayInitialStartup(){
Serial.println("Init LCD Start.");
lcd.init();
lcd.backlight();
createCustomChars();
lcd.setCursor(0,0);
lcd.write(' ');
lcd.write(' ');
if(lcd2004){
lcd.write(' ');
lcd.write(' ');
}
lcd.write(5);
if(lcd2004){
lcd.print(" Welcome! ");
}
else{
lcd.print(" Welcome ");
}
lcd.write(5);
delay(2000);
lcd.setCursor(0,1);
if(lcd2004){
lcd.write(' ');
lcd.write(' ');
}
lcd.print("ESP Stock Ticker");
delay(3000);
if(lcd2004){
lcd.setCursor(0,2);
lcd.write(' ');
lcd.write(' ');
lcd.write(' ');
lcd.write(5);
lcd.print(" Created By ");
lcd.write(5);
delay(1500);
lcd.setCursor(0,3);
lcd.write(' ');
lcd.write(' ');
lcd.write(2);
lcd.print("Billups Tillman");
}
else{
lcd.clear();
delay(1000);
lcd.setCursor(0,0);
lcd.write(' ');
lcd.write(5);
lcd.print(" Created By ");
lcd.write(5);
delay(2500);
lcd.setCursor(0,1);
lcd.print("Billups Tillman");
}
delay(introDelay);
Serial.println("Init LCD Complete.");
}
void displayStockResult(String ticker, float float_pchange, String currentPrice){
clearResetLCD();
if(lcd2004) printBorders();
if (float_pchange < 0){
lcd.write(6);
lcd.print(ticker + " ");
lcd.write(4);
lcd.write(' ');
lcd.print(String(float_pchange) + "%");
if(lcd2004) lcd.setCursor(0,2);
else lcd.setCursor(0,1);
lcd.write(6);
lcd.print(String(currentPrice));
}else{
lcd.write(6);
lcd.print(ticker + " ");
lcd.write(3);
lcd.write(' ');
lcd.print(String(float_pchange) + "%");
if(lcd2004) lcd.setCursor(0,2);
else lcd.setCursor(0,1);
lcd.write(6);
lcd.print(String(currentPrice));
}
}
void clearResetLCD(){
lcd.clear();
lcd.setCursor(0, 0);
}
void printBorders(){
lcd.setCursor(0,0);
for(int i = 0; i <= 20; i++){
lcd.write(7);
}
lcd.setCursor(0,3);
for(int i = 0; i <= 20; i++){
lcd.write(7);
}
lcd.setCursor(0,1);
}
void displayReconnectingCycle(){
clearResetLCD();
if(lcd2004){
printBorders();
lcd.write(' ');
lcd.write(' ');
}
lcd.print("Connecting...");
lcd.setCursor(0, 1);
if(lcd2004){
lcd.setCursor(0, 2);
int sent = 0;
while (sent < 20){
lcd.write(0);
delay(300);
sent++;
}
sent = 0;
while (sent < 19){
if (sent != 0){
lcd.setCursor(sent-1, 2);
lcd.write(0);
}
lcd.setCursor(sent+1, 2);
lcd.write(1);
delay(450);
sent++;
}
}
else{
int sent = 0;
while (sent < 15){
lcd.write(0);
delay(300);
sent++;
}
sent = 0;
while (sent < 14){
if (sent != 0){
lcd.setCursor(sent-1, 1);
lcd.write(0);
}
lcd.setCursor(sent+1, 1);
lcd.write(1);
delay(450);
sent++;
}
}
}
void displayWifiSuccess(){
clearResetLCD();
if(lcd2004){
printBorders();
lcd.write(' ');
lcd.write(' ');
}
lcd.print("WiFi Connected!");
if(lcd2004){
lcd.setCursor(0,2);
lcd.write(' ');
lcd.write(' ');
}
else lcd.setCursor(0,1);
int sent = 15;
while (sent > 0){
lcd.write(2);
delay(200);
sent--;
}
delay(500);
}