Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Matt aka Asmodeus
- //Created for arduino mega using sainsmart 3.2" touch screen display with adafruit gps v3
- //Motorcycle GPS Speedometer
- //Requires Fonts \/
- //1: http://www.henningkarlsen.com/electronics/dlfont.php?id=31&t=a
- //2: http://www.henningkarlsen.com/electronics/dlfont.php?id=7&t=a
- //Add the fonts to the UTFT FONT.c
- #include <Adafruit_GPS.h>
- #include <SoftwareSerial.h>
- #include <UTFT.h>
- #include <UTouch.h>
- SoftwareSerial mySerial(13, 11);
- UTFT myGLCD(ITDB32S,38,39,40,41);
- UTouch myTouch( 6, 5, 4, 3, 2);
- extern uint8_t LargeFont[]; //Huge Font
- extern uint8_t SmallFont[]; //Small Font
- extern uint8_t DingFont[]; //Icons Small
- extern uint8_t SwissFont[]; //Ghosty Type Font
- Adafruit_GPS GPS(&mySerial);
- #define GPSECHO true
- word colorlist[] = {
- VGA_WHITE, VGA_BLACK, VGA_RED, VGA_GREEN, VGA_BLUE};
- boolean usingInterrupt = false;
- void useInterrupt(boolean); // Func prototype keeps Arduino 0023 happy
- void select_Color(int col)
- {
- myGLCD.setColor(colorlist[col]);
- }
- void setup()
- {
- Serial.begin(115200);
- //GPS ECT
- GPS.begin(9600);
- GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
- GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
- GPS.sendCommand(PGCMD_ANTENNA);
- useInterrupt(true);
- delay(1000);
- mySerial.println(PMTK_Q_RELEASE);
- myGLCD.InitLCD();
- myGLCD.clrScr();
- myTouch.InitTouch();
- myTouch.setPrecision(PREC_HI);
- //Setup The Displays GUI
- myGLCD.setBackColor(VGA_TRANSPARENT);
- init_GUI();
- }
- String old_FIX = "x";
- String old_DEG = "x";
- String old_MPH = "x";
- String old_SAT = "x";
- String old_QUA = "x";
- String old_ALT = "x";
- String new_FIX = "x";
- String new_DEG = "x";
- String new_MPH = "x";
- String new_SAT = "x";
- String new_QUA = "x";
- String new_ALT = "x";
- String old_HOU = "x";
- String new_HOU = "x";
- String old_MIN = "x";
- String new_MIN = "x";
- String old_SEC = "x";
- String new_SEC = "x";
- String old_DAY = "x";
- String new_DAY = "x";
- String old_MON = "x";
- String new_MON = "x";
- String old_YEA = "x";
- String new_YEA = "x";
- int mode = 1;
- int words = 1;
- int back = 0;
- void init_GUI() {
- if(mode == 0)
- {
- words = 0;
- back = 1;
- myGLCD.setColor(VGA_BLACK);
- myGLCD.fillRect(0, 0, 319, 239);
- }
- else {
- words = 1;
- back = 0;
- myGLCD.setColor(VGA_WHITE);
- myGLCD.fillRect(0, 0, 319, 239);
- }
- //W = [CLOCK] DINGFONT
- //E = [HOUR GLASS] DINGFONT
- //} = [MOTORCYCLE] DINGFONT
- select_Color(3);
- myGLCD.drawRect(10 - 5, 235, 40 - 5, 225);
- myGLCD.drawRect(45 - 5, 235, 75 - 5, 215);
- myGLCD.drawRect(80 - 5, 235, 110 - 5, 205);
- myGLCD.drawRect(115 - 5,235, 145 - 5, 195);
- myGLCD.drawRect(150 - 5,235, 180 - 5, 185);
- myGLCD.drawRect(185 - 5,235, 215 - 5, 175);
- myGLCD.drawRect(220 - 5,235, 250 - 5, 165);
- myGLCD.drawRect(255 - 5,235, 285 - 5, 155);
- myGLCD.drawRect(290 - 5,235, 319 - 5, 145);
- select_Color(4);
- myGLCD.setFont(DingFont);
- myGLCD.print("#",286,5); //Day-Night Button Switch [Might add a LDR - Light Dependent Resistor]
- myGLCD.print("}",236,38); //Motorcycle Icon
- select_Color(words);
- myGLCD.setFont(SmallFont);
- myGLCD.print("Locate Fix:",10,10);
- myGLCD.print("Satellites:",10,20);
- myGLCD.setFont(SwissFont);
- myGLCD.print("MPH",190,45);
- myGLCD.setFont(SmallFont);
- myGLCD.print("Location:",10,30);
- myGLCD.print("Altitude:",10,40);
- old_FIX = "x";
- old_DEG = "x";
- old_MPH = "x";
- old_SAT = "x";
- old_QUA = "x";
- old_ALT = "x";
- new_FIX = "x";
- new_DEG = "x";
- new_MPH = "x";
- new_SAT = "x";
- new_QUA = "x";
- new_ALT = "x";
- old_HOU = "x";
- new_HOU = "x";
- old_MIN = "x";
- new_MIN = "x";
- old_SEC = "x";
- new_SEC = "x";
- old_DAY = "x";
- new_DAY = "x";
- old_MON = "x";
- new_MON = "x";
- old_YEA = "x";
- new_YEA = "x";
- }
- // Interrupt is called once a millisecond, looks for any new GPS data, and stores it
- SIGNAL(TIMER0_COMPA_vect) {
- char c = GPS.read();
- }
- void useInterrupt(boolean v) {
- if (v) {
- OCR0A = 0xAF;
- TIMSK0 |= _BV(OCIE0A);
- usingInterrupt = true;
- }
- else {
- TIMSK0 &= ~_BV(OCIE0A);
- usingInterrupt = false;
- }
- }
- int test_SPEED = 80;
- uint32_t timer = millis();
- void loop() // run over and over again
- {
- myGLCD.setBackColor(VGA_TRANSPARENT);
- // if a sentence is received, we can check the checksum, parse it...
- if (GPS.newNMEAreceived()) {
- if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false
- return; // we can fail to parse a sentence in which case we should just wait for another
- }
- // if millis() or timer wraps around, we'll just reset it
- if (timer > millis()) timer = millis();
- if (millis() - timer > 100) {
- timer = millis(); // reset the timer
- new_HOU = String(GPS.hour);
- new_MIN = String(GPS.minute);
- new_SEC = String(GPS.seconds);
- new_DAY = String(GPS.day);
- new_MON = String(GPS.month);
- new_YEA = String(GPS.year);
- new_FIX = String((int)GPS.fix);
- new_MPH = String(int((int)GPS.speed * 1.15078));
- new_DEG = String(GPS.latitudeDegrees,4) + "," + String(GPS.longitudeDegrees,4);
- new_SAT = String((int)GPS.satellites);
- new_ALT = String(GPS.altitude);
- new_QUA = String(GPS.fixquality);
- if(new_MIN.length() == 1) {
- new_MIN = "0" + new_MIN;
- }
- if(new_HOU.length() == 1) {
- new_HOU = "0" + new_HOU;
- }
- if(old_HOU != new_HOU || old_MIN != new_MIN)
- {
- myGLCD.setFont(SmallFont);
- select_Color(back);
- myGLCD.print("Time: " + old_HOU + ":" + old_MIN ,10,100);
- select_Color(words);
- myGLCD.print("Time: " + new_HOU + ":" + new_MIN ,10,100);
- old_HOU = new_HOU;
- old_MIN = new_MIN;
- old_SEC = new_SEC;
- }
- if(old_DAY != new_DAY || old_MON != new_MON || old_YEA != new_YEA)
- {
- myGLCD.setFont(SmallFont);
- select_Color(back);
- myGLCD.print("Date: " + old_DAY + "/" + old_MON + "/" + old_YEA,10,110);
- select_Color(words);
- myGLCD.print("Date: " + new_DAY + "/" + new_MON + "/" + new_YEA,10,110);
- old_DAY = new_DAY;
- old_MON = new_MON;
- old_YEA = new_YEA;
- }
- if(new_FIX == "1") {
- new_FIX = "Yes";
- }
- else {
- new_FIX = "No";
- }
- if (GPS.fix == 1) {
- myGLCD.setFont(SmallFont);
- select_Color(back);
- myGLCD.print("WAITING FOR FIX",10,50);
- myGLCD.setFont(DingFont);
- myGLCD.print("e",130,45);
- myGLCD.setFont(SmallFont);
- if(new_FIX != old_FIX) {
- select_Color(back);
- myGLCD.print(old_FIX,100,10);
- select_Color(words);
- myGLCD.print(new_FIX,100,10);
- old_FIX = new_FIX;
- }
- myGLCD.setFont(LargeFont);
- if(new_MPH != old_MPH) {
- select_Color(back);
- myGLCD.print(old_MPH,190,60);
- select_Color(words);
- myGLCD.print(new_MPH,190,60);
- old_MPH = new_MPH;
- }
- myGLCD.setFont(SmallFont);
- if(new_SAT != old_SAT) {
- select_Color(back);
- myGLCD.print(old_SAT,100,20);
- select_Color(words);
- myGLCD.print(new_SAT,100,20);
- old_SAT = new_SAT;
- }
- if(new_ALT != old_ALT) {
- select_Color(back);
- myGLCD.print(old_ALT,85,40);
- select_Color(words);
- myGLCD.print(new_ALT,85,40);
- old_ALT = new_ALT;
- }
- if(new_DEG != old_DEG) {
- select_Color(back);
- myGLCD.print(old_DEG,85,30);
- select_Color(words);
- myGLCD.print(new_DEG,85,30);
- old_DEG = new_DEG;
- }
- //SPEED BAR DISPLAY
- int SPEED_BAR = new_MPH.toInt();
- if(SPEED_BAR >= 10)
- { select_Color(4);
- myGLCD.fillRect(10 - 5 + 2, 235 - 2, 40 - 5 - 2, 225 + 2);
- } else { select_Color(back); myGLCD.fillRect(10 - 5 + 2, 235 - 2, 40 - 5 - 2, 225 + 2);}
- if(SPEED_BAR >= 20)
- { select_Color(4);
- myGLCD.fillRect(45 - 5 + 2, 235 - 2, 75 - 5 - 2, 215 + 2);
- } else { select_Color(back); myGLCD.fillRect(45 - 5 + 2, 235 - 2, 75 - 5 - 2, 215 + 2);}
- if(SPEED_BAR >= 30 )
- { select_Color(4);
- myGLCD.fillRect(80 - 5 + 2, 235 - 2, 110 - 5 - 2, 205 + 2);
- } else { select_Color(back); myGLCD.fillRect(80 - 5 + 2, 235 - 2, 110 - 5 - 2, 205 + 2);}
- if(SPEED_BAR >= 40)
- { select_Color(4);
- myGLCD.fillRect(115 - 5 + 2,235 - 2, 145 - 5 - 2, 195 + 2);
- } else { select_Color(back); myGLCD.fillRect(115 - 5 + 2,235 - 2, 145 - 5 - 2, 195 + 2);}
- if(SPEED_BAR >= 50)
- { select_Color(4);
- myGLCD.fillRect(150 - 5 + 2,235 - 2, 180 - 5 - 2, 185 + 2);
- } else { select_Color(back); myGLCD.fillRect(150 - 5 + 2,235 - 2, 180 - 5 - 2, 185 + 2);}
- if(SPEED_BAR >= 60)
- { select_Color(4);
- myGLCD.fillRect(185 - 5 + 2,235 - 2, 215 - 5 - 2, 175 + 2);
- } else { select_Color(back); myGLCD.fillRect(185 - 5 + 2,235 - 2, 215 - 5 - 2, 175 + 2);}
- if(SPEED_BAR >= 70)
- { select_Color(4);
- myGLCD.fillRect(220 - 5 + 2,235 - 2, 250 - 5 - 2, 165 + 2);
- } else { select_Color(back); myGLCD.fillRect(220 - 5 + 2,235 - 2, 250 - 5 - 2, 165 + 2);}
- if(SPEED_BAR >= 80)
- { select_Color(4);
- myGLCD.fillRect(255 - 5 + 2,235 - 2, 285 - 5 - 2, 155 + 2);
- } else { select_Color(back); myGLCD.fillRect(255 - 5 + 2,235 - 2, 285 - 5 - 2, 155 + 2);}
- if(SPEED_BAR >= 90)
- { select_Color(4);
- myGLCD.fillRect(290 - 5 + 2,235 - 2, 319 - 5 - 2, 145 + 2);
- } else { select_Color(back); myGLCD.fillRect(290 - 5 + 2,235 - 2, 319 - 5 - 2, 145 + 2);}
- }
- else {
- myGLCD.setFont(SmallFont);
- select_Color(2);
- myGLCD.print("WAITING FOR FIX",10,50);
- myGLCD.setFont(DingFont);
- myGLCD.print("e",130,45);
- myGLCD.setFont(SmallFont);
- if(new_FIX != old_FIX) {
- select_Color(back);
- myGLCD.print(old_FIX,100,10);
- select_Color(words);
- myGLCD.print(new_FIX,100,10);
- old_FIX = new_FIX;
- }
- if(new_SAT != old_SAT) {
- select_Color(back);
- myGLCD.print(old_SAT,100,20);
- select_Color(words);
- myGLCD.print(new_SAT,100,20);
- old_SAT = new_SAT;
- }
- }
- myGLCD.setBackColor(VGA_TRANSPARENT);
- }
- //DISPLAY TOUCH ECT
- long x, y;
- while (myTouch.dataAvailable() == true)
- {
- myTouch.read();
- x = myTouch.getX();
- y = myTouch.getY();
- //Day,Night Button
- if(x >= 300 && x <= myGLCD.getDisplayXSize() && y >= 0 && y <= 25)
- {
- if(mode == 0) {
- mode = 1;
- }
- else {
- mode = 0;
- }
- init_GUI();
- }
- test_SPEED -= 3;
- //vector on touch
- //select_Color(3);
- //myGLCD.fillRect(136,30,218,43);
- //select_Color(4);
- //myGLCD.print("X:" + String(myTouch.getX()),137,31);
- //myGLCD.print("Y:" + String(myTouch.getY()),178,31);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement