1
- #define MAP_WIDTH_PX 128
2
- #define MAP_HEIGHT_PX 103
1
+ #define MAP_WIDTH_PX 128 // Height of the map on the screen in pixels
2
+ #define MAP_HEIGHT_PX 103 // Width of the map on the screen in pixels
3
3
4
- #define MAP_MIN_LAT 51.49933 // bottom of map
5
- #define MAP_MAX_LAT 51.50922 // top of map
6
- #define MAP_MIN_LONG -0.14816 // left of map
7
- #define MAP_MAX_LONG -0.12059 // right of map
4
+ #define MAP_MIN_LAT 51.49933 // Bottom of map
5
+ #define MAP_MAX_LAT 51.50922 // Top of map
6
+ #define MAP_MIN_LONG -0.14816 // Left of map
7
+ #define MAP_MAX_LONG -0.12059 // Right of map
8
+
9
+ #define COLOUR_BACKGROUND QDTech_BLACK // Display background colour
10
+ #define COLOUR_BITMAP QDTech_WHITE // Colour of the map
11
+ #define COLOUR_TEXT QDTech_WHITE // Colour of the text
12
+ #define COLOUR_MAP_BORDER QDTech_WHITE // The colour used for the line which separates the map from the text below
13
+ #define COLOUR_LOCATION_CURRENT QDTech_RED // Colour of the pixel used to represent the current location on the map
14
+ #define COLOUR_LOCATION_HISTORY QDTech_GREEN // The colour of the line showing location history
15
+
16
+ #define TFT_ORIENTATION 0 // Orientation of TFT LCD 1.8" screen. 0 = Portrait, 1 = Landscape
17
+ #define UART_SERIAL_BAUD 1200 // Baud rate of the UART serial port (used for debugging)
18
+ #define SS_SERIAL_BAUD 1200 // Baud rate of the software serial port (used for wireless communication)
8
19
9
20
#define PING_BUTTON 4
10
21
#define REQUEST_GPS_ONCE_BUTTON 5
17
28
#define mosi 11 // Don't change
18
29
#define cs 10
19
30
#define dc A0
20
- #define rst A1 // you can also connect this to the Arduino reset
31
+ #define rst A1 // You can also connect this to the Arduino reset
21
32
22
33
#define _SS_MAX_RX_BUFF 128
23
34
#define SOFTWARE_SERIAL_RX 3
31
42
// Include the bitmap of the map. Location of the GPS tracker is drawn on the map
32
43
#include " mapBitmap.h"
33
44
34
- SoftwareSerial ss (SOFTWARE_SERIAL_RX, SOFTWARE_SERIAL_TX); // for HC-12 wireless communication module.
45
+ SoftwareSerial ss (SOFTWARE_SERIAL_RX, SOFTWARE_SERIAL_TX); // For HC-12 wireless communication module.
35
46
36
47
Adafruit_QDTech tft = Adafruit_QDTech(cs, dc, rst);
37
48
@@ -42,7 +53,7 @@ void transmit(String datatype, String data) {
42
53
tft.print (datatype + " :" + data);
43
54
ss.print (datatype + " :" + data + " \n " );
44
55
delay (1000 );
45
- tft.fillRect (5 * 6 , 13 * 8 , 17 * 6 , 1 * 8 , QDTech_BLACK ); // clear the transmitted text
56
+ tft.fillRect (5 * 6 , 13 * 8 , 17 * 6 , 1 * 8 , COLOUR_BACKGROUND ); // Clear the transmitted text
46
57
}
47
58
48
59
void blinkLED () {
@@ -74,21 +85,21 @@ void setCursorLine(unsigned int lineX, unsigned int lineY) {
74
85
}
75
86
76
87
void clearTFTGPS () {
77
- tft.fillRect (5 * 6 , 15 * 8 , 17 * 6 , 2 * 8 , QDTech_BLACK ); // clear lat and long
78
- tft.fillRect (5 * 6 , 17 * 8 , 6 * 6 , 3 * 8 , QDTech_BLACK ); // clear bottom left values
79
- tft.fillRect (16 * 6 , 17 * 8 , 6 * 6 , 3 * 8 , QDTech_BLACK ); // clear bottom right values
88
+ tft.fillRect (5 * 6 , 15 * 8 , 17 * 6 , 2 * 8 , COLOUR_BACKGROUND ); // clear lat and long
89
+ tft.fillRect (5 * 6 , 17 * 8 , 6 * 6 , 3 * 8 , COLOUR_BACKGROUND ); // clear bottom left values
90
+ tft.fillRect (16 * 6 , 17 * 8 , 6 * 6 , 3 * 8 , COLOUR_BACKGROUND ); // clear bottom right values
80
91
}
81
92
82
93
void clearTFTReceived () {
83
- tft.fillRect (5 * 6 , 14 * 8 , 17 * 6 , 1 * 8 , QDTech_BLACK ); // clear the received text
94
+ tft.fillRect (5 * 6 , 14 * 8 , 17 * 6 , 1 * 8 , COLOUR_BACKGROUND ); // clear the received text
84
95
}
85
96
86
97
void clearTFTMap () {
87
- tft.fillRect (0 , 0 , 128 , 103 , QDTech_BLACK ); // clear the map drawn on the TFT screen
98
+ tft.fillRect (0 , 0 , 128 , 103 , COLOUR_BACKGROUND ); // clear the map drawn on the TFT screen
88
99
}
89
100
90
101
void drawTFTMap () {
91
- tft.drawXBitmap (0 , 0 , mapBitmap, MAP_WIDTH_PX, MAP_HEIGHT_PX, QDTech_WHITE ); // Draw bitmap image
102
+ tft.drawXBitmap (0 , 0 , mapBitmap, MAP_WIDTH_PX, MAP_HEIGHT_PX, COLOUR_BITMAP ); // Draw bitmap image
92
103
}
93
104
94
105
void drawArrow (byte screenX, byte screenY, byte dir) {
@@ -101,28 +112,28 @@ void drawArrow(byte screenX, byte screenY, byte dir) {
101
112
switch (dir) {
102
113
case 0 : // NW
103
114
// fillTriangle(x0, y0, x1, y1, x2, y2, colour)
104
- tft.fillTriangle (screenX, screenY, screenX + 2 , screenY + 5 , screenX + 5 , screenY + 2 , QDTech_RED );
115
+ tft.fillTriangle (screenX, screenY, screenX + 2 , screenY + 5 , screenX + 5 , screenY + 2 , COLOUR_LOCATION_CURRENT );
105
116
break ;
106
117
case 1 : // N
107
- tft.fillTriangle (screenX, screenY, screenX - 2 , screenY + 5 , screenX + 2 , screenY + 5 , QDTech_RED );
118
+ tft.fillTriangle (screenX, screenY, screenX - 2 , screenY + 5 , screenX + 2 , screenY + 5 , COLOUR_LOCATION_CURRENT );
108
119
break ;
109
120
case 2 : // NE
110
- tft.fillTriangle (screenX, screenY, screenX - 2 , screenY + 5 , screenX - 5 , screenY + 2 , QDTech_RED );
121
+ tft.fillTriangle (screenX, screenY, screenX - 2 , screenY + 5 , screenX - 5 , screenY + 2 , COLOUR_LOCATION_CURRENT );
111
122
break ;
112
123
case 3 : // E
113
- tft.fillTriangle (screenX, screenY, screenX - 5 , screenY - 2 , screenX - 5 , screenY + 2 , QDTech_RED );
124
+ tft.fillTriangle (screenX, screenY, screenX - 5 , screenY - 2 , screenX - 5 , screenY + 2 , COLOUR_LOCATION_CURRENT );
114
125
break ;
115
126
case 4 : // SE
116
- tft.fillTriangle (screenX, screenY, screenX - 2 , screenY - 5 , screenX - 5 , screenY - 2 , QDTech_RED );
127
+ tft.fillTriangle (screenX, screenY, screenX - 2 , screenY - 5 , screenX - 5 , screenY - 2 , COLOUR_LOCATION_CURRENT );
117
128
break ;
118
129
case 5 : // S
119
- tft.fillTriangle (screenX, screenY, screenX + 2 , screenY - 5 , screenX - 2 , screenY - 5 , QDTech_RED );
130
+ tft.fillTriangle (screenX, screenY, screenX + 2 , screenY - 5 , screenX - 2 , screenY - 5 , COLOUR_LOCATION_CURRENT );
120
131
break ;
121
132
case 6 : // SW
122
- tft.fillTriangle (screenX, screenY, screenX + 2 , screenY - 5 , screenX + 5 , screenY - 2 , QDTech_RED );
133
+ tft.fillTriangle (screenX, screenY, screenX + 2 , screenY - 5 , screenX + 5 , screenY - 2 , COLOUR_LOCATION_CURRENT );
123
134
break ;
124
135
case 7 : // W
125
- tft.fillTriangle (screenX, screenY, screenX + 5 , screenY + 2 , screenX + 5 , screenY - 2 , QDTech_RED );
136
+ tft.fillTriangle (screenX, screenY, screenX + 5 , screenY + 2 , screenX + 5 , screenY - 2 , COLOUR_LOCATION_CURRENT );
126
137
break ;
127
138
}
128
139
}
@@ -150,24 +161,24 @@ void displayLocationOnMap(float currentLatitude, float currentLongitude) {
150
161
// if tracker is on-screen
151
162
if (relativeXPosOnMap >= 0 && relativeXPosOnMap <= 1 && relativeYPosOnMap >= 0 && relativeYPosOnMap <= 1 ) {
152
163
// Draw pixel on map at previous coordinates for plot of location history
153
- tft.drawPixel (previousCoordinates[0 ], previousCoordinates[1 ], QDTech_BLACK ); // Clear the pixel first
154
- tft.drawPixel (previousCoordinates[0 ], previousCoordinates[1 ], QDTech_GREEN );
164
+ tft.drawPixel (previousCoordinates[0 ], previousCoordinates[1 ], COLOUR_BACKGROUND ); // Clear the pixel first
165
+ tft.drawPixel (previousCoordinates[0 ], previousCoordinates[1 ], COLOUR_LOCATION_HISTORY );
155
166
156
167
// Draw pixel on map at current location
157
- tft.drawPixel (screenXPos, screenYPos, QDTech_BLACK ); // Clear the pixel first
158
- tft.drawPixel (screenXPos, screenYPos, QDTech_RED );
168
+ tft.drawPixel (screenXPos, screenYPos, COLOUR_BACKGROUND ); // Clear the pixel first
169
+ tft.drawPixel (screenXPos, screenYPos, COLOUR_LOCATION_CURRENT );
159
170
160
171
// Uncomment to draw a '+' of pixels around location (May break line on graph showing tracker's location history)
161
- // tft.drawPixel(screenXPos + 1, screenYPos , QDTech_RED );
162
- // tft.drawPixel(screenXPos - 1, screenYPos , QDTech_RED );
163
- // tft.drawPixel(screenXPos , screenYPos + 1, QDTech_RED );
164
- // tft.drawPixel(screenXPos , screenYPos - 1, QDTech_RED );
172
+ // tft.drawPixel(screenXPos + 1, screenYPos , COLOUR_LOCATION_CURRENT );
173
+ // tft.drawPixel(screenXPos - 1, screenYPos , COLOUR_LOCATION_CURRENT );
174
+ // tft.drawPixel(screenXPos , screenYPos + 1, COLOUR_LOCATION_CURRENT );
175
+ // tft.drawPixel(screenXPos , screenYPos - 1, COLOUR_LOCATION_CURRENT );
165
176
166
177
// Uncomment to draw a 'x' of pixels around location (May break line on graph showing tracker's location history)
167
- // tft.drawPixel(screenXPos-1, screenYPos-1, QDTech_RED );
168
- // tft.drawPixel(screenXPos-1, screenYPos+1, QDTech_RED );
169
- // tft.drawPixel(screenXPos+1, screenYPos+1, QDTech_RED );
170
- // tft.drawPixel(screenXPos+1, screenYPos-1, QDTech_RED );
178
+ // tft.drawPixel(screenXPos-1, screenYPos-1, COLOUR_LOCATION_CURRENT );
179
+ // tft.drawPixel(screenXPos-1, screenYPos+1, COLOUR_LOCATION_CURRENT );
180
+ // tft.drawPixel(screenXPos+1, screenYPos+1, COLOUR_LOCATION_CURRENT );
181
+ // tft.drawPixel(screenXPos+1, screenYPos-1, COLOUR_LOCATION_CURRENT );
171
182
172
183
// Set previousCoordinates to current location for next time
173
184
previousCoordinates[0 ] = screenXPos;
@@ -214,20 +225,20 @@ void setup() {
214
225
pinMode (REQUEST_GPS_STOP_BUTTON, INPUT_PULLUP);
215
226
pinMode (REDRAW_MAP_BUTTON, INPUT_PULLUP);
216
227
217
- // Serial.begin(1200 ); //For debugging
218
- ss.begin (1200 ); // For HC-12 wireless communication module
228
+ // Serial.begin(UART_SERIAL_BAUD ); //For debugging
229
+ ss.begin (SS_SERIAL_BAUD ); // For HC-12 wireless communication module
219
230
220
231
tft.init ();
221
- tft.setRotation (0 ); // 0 = Portrait, 1 = Landscape
222
- tft.fillScreen (QDTech_BLACK );
232
+ tft.setRotation (TFT_ORIENTATION);
233
+ tft.fillScreen (COLOUR_BACKGROUND );
223
234
tft.setTextWrap (false );
224
235
tft.setCursor (0 , 0 );
225
- tft.setTextColor (QDTech_WHITE );
236
+ tft.setTextColor (COLOUR_TEXT );
226
237
tft.setTextSize (1 );
227
238
228
239
// DRAW BITMAP IMAGE AND PRINT VALUE TITLES
229
240
drawTFTMap ();
230
- tft.drawFastHLine (0 , 103 , 128 , QDTech_WHITE ); // Note: draw on line 103, which is the 104th line
241
+ tft.drawFastHLine (0 , 103 , 128 , COLOUR_MAP_BORDER ); // Note: draw on line 103, which is the 104th line
231
242
setCursorLine (0 , 13 ); // Print titles for values
232
243
tft.println (" Sent:" );
233
244
tft.println (" Rcvd:" );
0 commit comments