-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWall-E_LCD_Screen.ino
303 lines (244 loc) · 10.8 KB
/
Wall-E_LCD_Screen.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
//--------------------------------------------------------------------
//--------------------------------------------------------------------
//
// WALL-E LCD Screen & Battery Monitor
// Original code by Dan C.
// http://wallebuilders.club
//
//--------------------------------------------------------------------
//--------------------------------------------------------------------
//--------------------------------------------------------------------
// Hardware Required:
//
// 5.0in 800x480 TFT display - Adafruit (or Aliexpress clone)
// Adafruit RA8875 display driver board
// Arduino Uno/Mega/Nano
// Voltage monitor or divider (board or DIY - required only for battery level monitoring)
//
//--------------------------------------------------------------------
//--------------------------------------------------------------------
// Libraries
//--------------------------------------------------------------------
#include <SPI.h>
#include "Adafruit_GFX.h"
#include "Adafruit_RA8875.h"
#include "bmp.h" // Image file
// RA8875 Library only supports hardware SPI at this time
// Connect SCK to UNO Digital #13 (Hardware SPI clock)
// Connect MISO to UNO Digital #12 (Hardware SPI MISO)
// Connect MOSI to UNO Digital #11 (Hardware SPI MOSI)
// Connect CS or SS to UNO Digital #10 (Hardware SPI SS)
// Connect SCK to Mega2560 Digital #52 (Hardware SPI clock)
// Connect MISO to Mega2560 Digital #50 (Hardware SPI MISO)
// Connect MOSI to Mega2560 Digital #51 (Hardware SPI MOSI)
// Connect CS or SS to Mega2560 Digital #53 (Hardware SPI SS)
// Connect SCK to Nano Digital #13 (Hardware SPI SCK)
// Connect MISO to Nano Digital #12 (Hardware SPI MISO)
// Connect MOSI to Nano Digital #11 (Hardware SPI MOSI)
// Connect CS or SS to Nano Digital #10 (Hardware SPI CS)
// Connect Signal wire from Voltage divider into pin A0
#define RA8875_CS 10 // 53 on Mega2560, 10 on Uno, 10 on Nano
#define RA8875_RESET 9 // any didgital pin
Adafruit_RA8875 tft = Adafruit_RA8875(RA8875_CS, RA8875_RESET);
#define RA8875_DARKERGRAY 0x333333 // change color of background boxes
//--------------------------------------------------------------------
// Variables/Constants
//--------------------------------------------------------------------
const unsigned long powercheckdelay = 1000; // Delay for power level check once a second.
int voltageSensor1 = A0;
unsigned long currentMillis = 0;
unsigned long powerMillis = 0;
float vOUT1 = 0.0;
float vIN1 = 0.0;
float R11 = 30000; // 30000 adjust to exact value for more accurate reading
float R22 = 7500; // 7500 adjust to exact value for more accurate reading
int value1 = 0;
byte booted = 0;
byte round_corner = 4;
byte start_x = 90; //Moves LCD display Up or Down on display
#define Playbutton 6
#define Stopbutton 7
#define Recordbutton 8
#define Lightbutton 5
//--------------------------------------------------------------------
// SETUP
//--------------------------------------------------------------------
void setup()
{
Serial.begin(9600); // Debug Console
// initialize the Electroncis Panel pushbutton pins as an input:
pinMode(Playbutton, INPUT_PULLUP);
pinMode(Stopbutton, INPUT_PULLUP);
pinMode(Recordbutton, INPUT_PULLUP);
pinMode(Lightbutton, INPUT_PULLUP);
pinMode(A0, INPUT);
/* Initialize the display using 'RA8875_480x80', 'RA8875_480x128', 'RA8875_480x272' or 'RA8875_800x480' */
if (!tft.begin(RA8875_800x480)) {
Serial.println("RA8875 Not Found!");
while (1);
}
tft.displayOn(true);
tft.GPIOX(true); // Enable TFT - display enable tied to GPIOX
tft.PWM1config(true, RA8875_PWM_CLK_DIV1024); // PWM output for backlight
tft.PWM1out(255); // Set Display Brightness to maximum
tft.setRotation(3); // 0,1,2 or 3 Changes screen rotation
tft.fillScreen(RA8875_BLACK); // Clear the Screen
tft.drawBitmap(start_x + 0, 0, sclbmp, 32, 480,RA8875_YELLOW);
tft.drawBitmap(start_x + 77, 337, sun, 144, 144,RA8875_YELLOW);
tft.fillRoundRect(start_x + 483, 0, 71, 294, round_corner, RA8875_DARKERGRAY);
tft.fillRoundRect(start_x + 438, 0, 20, 294, round_corner, RA8875_DARKERGRAY);
tft.fillRoundRect(start_x + 393, 0, 20, 294, round_corner, RA8875_DARKERGRAY);
tft.fillRoundRect(start_x + 348, 0, 20, 294, round_corner, RA8875_DARKERGRAY);
tft.fillRoundRect(start_x + 303, 0, 20, 294, round_corner, RA8875_DARKERGRAY);
tft.fillRoundRect(start_x + 258, 0, 20, 294, round_corner, RA8875_DARKERGRAY);
tft.fillRoundRect(start_x + 213, 0, 20, 294, round_corner, RA8875_DARKERGRAY);
tft.fillRoundRect(start_x + 168, 0, 20, 294, round_corner, RA8875_DARKERGRAY);
tft.fillRoundRect(start_x + 123, 0, 20, 294, round_corner, RA8875_DARKERGRAY);
tft.fillRoundRect(start_x + 78, 0, 20, 294, round_corner, RA8875_DARKERGRAY);
delay(2000); // adjust delay as needed to adjust sound timing
boot_sequence();
}
//********************************** END SETUP ***********************************//
void(* resetFunc) (void) = 0;//declare reset function at address 0
//--------------------------------------------------------------------
// LOOP START
//--------------------------------------------------------------------
void loop()
{
currentMillis = millis();
//--------------------------------------------------------------------
// Battery Monitoring
//--------------------------------------------------------------------
if (currentMillis - powerMillis >= powercheckdelay) // Runs power check once a second.
{
value1 = analogRead(voltageSensor1); // onboard lipo battery monitor
vOUT1 = (value1 * 5.0) / 1024.0;
vIN1 = vOUT1/(R22/(R11+R22));
powerMillis = currentMillis;
}
// Note: Battery voltage monitoring setup for a 60AH LifeP04 Battery. Adjust accordingly.
if(vIN1 >= 11){ // Line 1
tft.fillRoundRect(start_x + 483, 0, 71, 294, round_corner, RA8875_YELLOW);
} else {
tft.fillRoundRect(start_x + 483, 0, 71, 294, round_corner, RA8875_DARKERGRAY);
}
if(vIN1 >= 11.25){ // Line 2
tft.fillRoundRect(start_x + 438, 0, 20, 294, round_corner, RA8875_YELLOW);
} else {
tft.fillRoundRect(start_x + 438, 0, 20, 294, round_corner, RA8875_DARKERGRAY);
}
if(vIN1 >= 11.5){ // Line 3
tft.fillRoundRect(start_x + 393, 0, 20, 294, round_corner, RA8875_YELLOW);
} else {
tft.fillRoundRect(start_x + 393, 0, 20, 294, round_corner, RA8875_DARKERGRAY);
}
if(vIN1 >= 11.75){ // Line 4
tft.fillRoundRect(start_x + 348, 0, 20, 294, round_corner, RA8875_YELLOW);
} else {
tft.fillRoundRect(start_x + 348, 0, 20, 294, round_corner, RA8875_DARKERGRAY);
}
if(vIN1 >= 12){ // Line 5
tft.fillRoundRect(start_x + 303, 0, 20, 294, round_corner, RA8875_YELLOW);
} else {
tft.fillRoundRect(start_x + 303, 0, 20, 294, round_corner, RA8875_DARKERGRAY);
}
if(vIN1 >= 12.25){ // Line 6
tft.fillRoundRect(start_x + 258, 0, 20, 294, round_corner, RA8875_YELLOW);
} else {
tft.fillRoundRect(start_x + 258, 0, 20, 294, round_corner, RA8875_DARKERGRAY);
}
if(vIN1 >= 12.5){ // Line 7
tft.fillRoundRect(start_x + 213, 0, 20, 294, round_corner, RA8875_YELLOW);
} else {
tft.fillRoundRect(start_x + 213, 0, 20, 294, round_corner, RA8875_DARKERGRAY);;
}
if(vIN1 >= 12.75){ // Line 8
tft.fillRoundRect(start_x + 168, 0, 20, 294, round_corner, RA8875_YELLOW);
} else {
tft.fillRoundRect(start_x + 168, 0, 20, 294, round_corner, RA8875_DARKERGRAY);
}
if(vIN1 >= 13){ // Line 9
tft.fillRoundRect(start_x + 123, 0, 20, 294, round_corner, RA8875_YELLOW);
} else {
tft.fillRoundRect(start_x + 123, 0, 20, 294, round_corner, RA8875_DARKERGRAY);
}
if(vIN1 >= 13.25){ // Line 10
tft.fillRoundRect(start_x + 78, 0, 20, 294, round_corner, RA8875_YELLOW);
} else {
tft.fillRoundRect(start_x + 78, 0, 20, 294, round_corner, RA8875_DARKERGRAY);
}
Serial.print(vIN1);
//--------------------------------------------------------------------
// Electroncis Panel buttons
//--------------------------------------------------------------------
// read the state of the electroncis panel pushbutton values:
int recordbuttonState = digitalRead(Recordbutton);
int playbuttonState = digitalRead(Playbutton);
int stopbuttonState = digitalRead(Stopbutton);
int lightbuttonState = digitalRead(Lightbutton);
if (recordbuttonState == LOW)
{
Serial.print("v, Record on, ");
// Place code here for action
}
else
{
Serial.print("v Record off, ");
// Place code here for action
}
if (playbuttonState == LOW)
{
Serial.print("Play on, ");
// Place code here for action
}
else
{
Serial.print("Play off, ");
// Place code here for action
}
if (stopbuttonState == LOW)
{
Serial.print("Stop on, ");
resetFunc(); //call reset
}
else
{
Serial.print("Stop off, ");
// Place code here for action
}
if (lightbuttonState == LOW)
{
Serial.println("Light on");
// Place code here for action
}
else
{
Serial.println("Light off");
// Place code here for action
}
} //=================End Loop========================
void boot_sequence(){
// Start Boot Sequence by turning the display ON
tft.displayOn(true);
delay(1000);
tft.fillRoundRect(start_x + 483, 0, 71, 294, round_corner, RA8875_YELLOW); // Line 1
delay(1000);
tft.fillRoundRect(start_x + 438, 0, 20, 294, round_corner, RA8875_YELLOW); // Line 2
delay(700);
tft.fillRoundRect(start_x + 393, 0, 20, 294, round_corner, RA8875_YELLOW); // Line 3
delay(650);
tft.fillRoundRect(start_x + 348, 0, 20, 294, round_corner, RA8875_YELLOW); // Line 4
delay(600);
tft.fillRoundRect(start_x + 303, 0, 20, 294, round_corner, RA8875_YELLOW); // Line 5
delay(550);
tft.fillRoundRect(start_x + 258, 0, 20, 294, round_corner, RA8875_YELLOW); // Line 6
delay(450);
tft.fillRoundRect(start_x + 213, 0, 20, 294, round_corner, RA8875_YELLOW); // Line 7
delay(400);
tft.fillRoundRect(start_x + 168, 0, 20, 294, round_corner, RA8875_YELLOW); // Line 8
delay(350);
tft.fillRoundRect(start_x + 123, 0, 20, 294, round_corner, RA8875_YELLOW); // Line 9
delay(250);
tft.fillRoundRect(start_x + 78, 0, 20, 294, round_corner, RA8875_YELLOW); // Line 10
delay(5000);
}