-
Notifications
You must be signed in to change notification settings - Fork 1
/
LCD.ino
196 lines (151 loc) · 4.01 KB
/
LCD.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
#include <Adafruit_TFTLCD.h>
#include <Adafruit_GFX.h>
#include <TouchScreen.h>
#include <Wire.h>
#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4
#define TS_MINX 122
#define TS_MINY 111
#define TS_MAXX 942
#define TS_MAXY 890
#define YP A3
#define XM A2
#define YM 9
#define XP 8
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 364);
boolean buttonEnabled = true;
int frequency=0;
String state = "UNMUTED";
double stations[] = {100.6, 104.2,90.90};
int currentstation = 0;
int Txcommand = 0;
void setup() {
Wire.begin(5);
Wire.onRequest(requestEvent);
tft.reset();
uint16_t identifier = tft.readID();
tft.begin(identifier);
tft.setRotation(1);
tft.fillScreen(WHITE);
tft.drawRect(0,0,319,240,BLACK);
tft.setCursor(30,20);
tft.setTextColor(BLACK);
tft.setTextSize(2);
tft.print("SMART CAR CONTROLLER");
//Frequency Incrementer
tft.fillRect(250,50, 40, 40, RED);
tft.drawRect(250,50,40,40,BLACK);
tft.setCursor(263,60);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.print("+");
//Frequency Decrementer
tft.fillRect(250,100, 40, 40, RED);
tft.drawRect(250,100,40,40,BLACK);
tft.setCursor(263,110);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.print("-");
//Frequency Viewer
tft.fillRect(205,75, 40, 40, WHITE);
tft.drawRect(205,75,40,40,BLACK);
//Mute
tft.fillRect(30,175, 60, 40, BLUE);
tft.drawRect(30,175,60,40,BLACK);
tft.setCursor(38,185);
tft.setTextColor(BLACK);
tft.setTextSize(2);
tft.print("MUTE");
//UnMute
tft.fillRect(120,175, 90, 40, BLUE);
tft.drawRect(120,175,90,40,BLACK);
tft.setCursor(128,185);
tft.setTextColor(BLACK);
tft.setTextSize(2);
tft.print("UNMUTE");
//UnMute
tft.fillRect(70,125, 100, 40, WHITE);
tft.drawRect(70,125,100,40,BLACK);
tft.setCursor(78,135);
tft.setTextColor(BLACK);
tft.setTextSize(2);
tft.print("UNMUTED");
}
void requestEvent() {
Wire.write(Txcommand);
}
void loop() {
TSPoint p = ts.getPoint();
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
if (p.z > ts.pressureThreshhold) {
p.x = map(p.x, TS_MAXX, TS_MINX, 0, 320);
p.y = map(p.y, TS_MAXY, TS_MINY, 0, 480);
/*String y = String(p.y);
String x = String(p.x);
tft.fillRect(150,150, 40, 40, WHITE);
tft.drawRect(150,150,40,40,BLACK);
tft.setCursor(160,160);
tft.setTextColor(BLACK);
tft.setTextSize(1);
tft.print(x);
tft.fillRect(200,150, 40, 40, WHITE);
tft.drawRect(200,150,40,40,BLACK);
tft.setCursor(210,160);
tft.setTextColor(BLACK);
tft.setTextSize(1);
tft.print(y);
*/
if(p.x>74 && p.x<120 && p.y>398 && p.y<455 && buttonEnabled){
buttonEnabled = false;
if(currentstation<2){
currentstation++;
}
Txcommand = currentstation;
}
if(p.x>144 && p.x<195 && p.y>398 && p.y<455 && buttonEnabled){
buttonEnabled = false;
if(currentstation>0){
currentstation--;
}
Txcommand = currentstation;
}
if(p.x>245 && p.x<300 && p.y>40 && p.y<140 && buttonEnabled){
buttonEnabled = false;
state = "MUTED";
Txcommand = 3;
}
if(p.x>245 && p.x<300 && p.y>186 && p.y<330 && buttonEnabled){
buttonEnabled = false;
state = "UNMUTED";
Txcommand = 4;
}
}else if (p.z < ts.pressureThreshhold) {
buttonEnabled = true;
}
String f = String(stations[currentstation]);
tft.fillRect(205,75, 40, 40, WHITE);
tft.drawRect(205,75,40,40,BLACK);
tft.setCursor(215,85);
tft.setTextColor(BLACK);
tft.setTextSize(1);
tft.print(f);
tft.fillRect(70,125, 100, 40, WHITE);
tft.drawRect(70,125,100,40,BLACK);
tft.setCursor(78,135);
tft.setTextColor(BLACK);
tft.setTextSize(2);
tft.print(state);
}