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
33
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)
819
920#define PING_BUTTON 4
1021#define REQUEST_GPS_ONCE_BUTTON 5
1728#define mosi 11 // Don't change
1829#define cs 10
1930#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
2132
2233#define _SS_MAX_RX_BUFF 128
2334#define SOFTWARE_SERIAL_RX 3
3142// Include the bitmap of the map. Location of the GPS tracker is drawn on the map
3243#include " mapBitmap.h"
3344
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.
3546
3647Adafruit_QDTech tft = Adafruit_QDTech(cs, dc, rst);
3748
@@ -42,7 +53,7 @@ void transmit(String datatype, String data) {
4253 tft.print (datatype + " :" + data);
4354 ss.print (datatype + " :" + data + " \n " );
4455 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
4657}
4758
4859void blinkLED () {
@@ -74,21 +85,21 @@ void setCursorLine(unsigned int lineX, unsigned int lineY) {
7485}
7586
7687void 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
8091}
8192
8293void 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
8495}
8596
8697void 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
8899}
89100
90101void 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
92103}
93104
94105void drawArrow (byte screenX, byte screenY, byte dir) {
@@ -101,28 +112,28 @@ void drawArrow(byte screenX, byte screenY, byte dir) {
101112 switch (dir) {
102113 case 0 : // NW
103114 // 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 );
105116 break ;
106117 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 );
108119 break ;
109120 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 );
111122 break ;
112123 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 );
114125 break ;
115126 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 );
117128 break ;
118129 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 );
120131 break ;
121132 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 );
123134 break ;
124135 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 );
126137 break ;
127138 }
128139}
@@ -150,24 +161,24 @@ void displayLocationOnMap(float currentLatitude, float currentLongitude) {
150161 // if tracker is on-screen
151162 if (relativeXPosOnMap >= 0 && relativeXPosOnMap <= 1 && relativeYPosOnMap >= 0 && relativeYPosOnMap <= 1 ) {
152163 // 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 );
155166
156167 // 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 );
159170
160171 // 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 );
165176
166177 // 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 );
171182
172183 // Set previousCoordinates to current location for next time
173184 previousCoordinates[0 ] = screenXPos;
@@ -214,20 +225,20 @@ void setup() {
214225 pinMode (REQUEST_GPS_STOP_BUTTON, INPUT_PULLUP);
215226 pinMode (REDRAW_MAP_BUTTON, INPUT_PULLUP);
216227
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
219230
220231 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 );
223234 tft.setTextWrap (false );
224235 tft.setCursor (0 , 0 );
225- tft.setTextColor (QDTech_WHITE );
236+ tft.setTextColor (COLOUR_TEXT );
226237 tft.setTextSize (1 );
227238
228239 // DRAW BITMAP IMAGE AND PRINT VALUE TITLES
229240 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
231242 setCursorLine (0 , 13 ); // Print titles for values
232243 tft.println (" Sent:" );
233244 tft.println (" Rcvd:" );
0 commit comments