-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLCDscreen
196 lines (163 loc) · 5.42 KB
/
LCDscreen
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
// Facial expression animations on ELEGOO TFT LCD screen for Minibot
#include <Elegoo_GFX.h> // Core graphics library
#include <Elegoo_TFTLCD.h> // Hardware-specific library
#include <TouchScreen.h>
//--------------------- define ----------------------------
#if defined(__SAM3X8E__)
#undef __FlashStringHelper::F(string_literal)
#define F(string_literal) string_literal
#endif
#define YP A3 // must be an analog pin, use "An" notation!
#define XM A2 // must be an analog pin, use "An" notation!
#define YM 9 // can be a digital pin
#define XP 8 // can be a digital pin
#define TS_MINX 120
#define TS_MAXX 900
#define TS_MINY 70
#define TS_MAXY 920
// For better pressure precision, we need to know the resistance
// between X+ and X- Use any multimeter to read it
// For the one we're using, its 300 ohms across the X plate
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
// optional
#define LCD_RESET A4
// Assign human-readable names to some common 16-bit color values:
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
Elegoo_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
#define BOXSIZE 40
//------------------- define functions -----------------------
void Angry(){
tft.fillRect(100, 120, BOXSIZE, BOXSIZE, RED);
tft.fillRect(100, 240, BOXSIZE, BOXSIZE, RED);
delay(1000);
tft.fillRect(100, 120, BOXSIZE, BOXSIZE, YELLOW);
tft.fillRect(100, 240, BOXSIZE, BOXSIZE, YELLOW);
}
void Blink(){
tft.fillRect(110, 120, BOXSIZE, BOXSIZE, BLACK);
tft.fillRect(110, 240, BOXSIZE, BOXSIZE, BLACK);
delay(1000);
tft.fillRect(100, 120, BOXSIZE, BOXSIZE, YELLOW);
tft.fillRect(100, 240, BOXSIZE, BOXSIZE, YELLOW);
}
void Cry(){
tft.fillRect(100, 120, 10, BOXSIZE, BLUE);
tft.fillRect(100, 240, 10, BOXSIZE, BLUE);
delay(500);
tft.fillRect(80, 120, 20, 10, BLUE);
tft.fillRect(80, 270, 20, 10, BLUE);
delay(500);
tft.fillRect(60, 120, 20, 10, BLUE);
tft.fillRect(60, 270, 20, 10, BLUE);
delay(500);
tft.fillRect(40, 120, 20, 10, BLUE);
tft.fillRect(40, 270, 20, 10, BLUE);
delay(500);
tft.fillRect(20, 120, 20, 10, BLUE);
tft.fillRect(20, 270, 20, 10, BLUE);
delay(500);
tft.fillRect(00, 120, 20, 10, BLUE);
tft.fillRect(00, 270, 20, 10, BLUE);
}
void Correct(){
tft.fillRect(90, 110, 60, 60, GREEN);
tft.fillRect(90, 230, 60, 60, GREEN);
delay(1000);
tft.fillRect(90, 110, 60, 60, BLACK);
tft.fillRect(90, 230, 60, 60, BLACK);
tft.fillRect(100, 120, BOXSIZE, BOXSIZE, YELLOW);
tft.fillRect(100, 240, BOXSIZE, BOXSIZE, YELLOW);
}
void Sketchy(){
tft.fillRect(90, 110, 60, 60, BLACK);
tft.fillRect(90, 230, 60, 60, BLACK);
tft.fillRect(110, 120, 20, BOXSIZE, YELLOW);
tft.fillRect(110, 240, 20, BOXSIZE, YELLOW);
delay(1000);
tft.fillRect(110, 140, 20, 20, BLACK);
tft.fillRect(110, 260, 20, 20, BLACK);
delay(500);
tft.fillRect(110, 120, 20, BOXSIZE, YELLOW);
tft.fillRect(110, 240, 20, BOXSIZE, YELLOW);
tft.fillRect(110, 120, 20, 20, BLACK);
tft.fillRect(110, 240, 20, 20, BLACK);
delay(1000);
tft.fillRect(110, 120, 20, BOXSIZE, YELLOW);
tft.fillRect(110, 240, 20, BOXSIZE, YELLOW);
}
//-------------- code from tutorial/manual -------------------
void setup(void) {
Serial.begin(9600);
Serial.println(F("Pet me"));
tft.reset();
uint16_t identifier = tft.readID();
if(identifier == 0x9325) {
Serial.println(F("Found ILI9325 LCD driver"));
} else if(identifier == 0x9328) {
Serial.println(F("Found ILI9328 LCD driver"));
} else if(identifier == 0x4535) {
Serial.println(F("Found LGDP4535 LCD driver"));
}else if(identifier == 0x7575) {
Serial.println(F("Found HX8347G LCD driver"));
} else if(identifier == 0x9341) {
Serial.println(F("Found ILI9341 LCD driver"));
} else if(identifier == 0x8357) {
Serial.println(F("Found HX8357D LCD driver"));
} else if(identifier==0x0101)
{
identifier=0x9341;
Serial.println(F("Found 0x9341 LCD driver"));
}else {
Serial.print(F("Unknown LCD driver chip: "));
Serial.println(identifier, HEX);
Serial.println(F("If using the Elegoo 2.8\" TFT Arduino shield, the line:"));
Serial.println(F(" #define USE_Elegoo_SHIELD_PINOUT"));
Serial.println(F("should appear in the library header (Elegoo_TFT.h)."));
Serial.println(F("If using the breakout board, it should NOT be #defined!"));
Serial.println(F("Also if using the breakout, double-check that all wiring"));
Serial.println(F("matches the tutorial."));
identifier=0x9341;
}
//--------------------- setup screen -------------------------
tft.begin(identifier);
tft.setRotation(2);
tft.fillScreen(BLACK);
tft.fillRect(100, 120, BOXSIZE, BOXSIZE, YELLOW);
tft.fillRect(100, 240, BOXSIZE, BOXSIZE, YELLOW);
delay(1000);
pinMode(13, OUTPUT);
}
//--------------------- touchscreen -------------------------
#define MINPRESSURE 10
#define MAXPRESSURE 1000
#define MEDPRESSURE 500
int counter = 0;
void loop()
{
digitalWrite(13, HIGH);
TSPoint p = ts.getPoint();
digitalWrite(13, LOW);
//pinMode(XP, OUTPUT);
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
//pinMode(YM, OUTPUT);
if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
counter++;
if (counter == 5){
Angry();
counter = 0;
}
Blink();
}
}