Created
November 23, 2015 15:10
-
-
Save andfoy/32379cbd099f961fb539 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <Wire.h> | |
| #include <string.h> | |
| //#include <AltSoftSerial.h> | |
| /** | |
| Macro definitions | |
| **/ | |
| #define Task_t 10 // Task Time in milli seconds | |
| /** | |
| String definitions | |
| **/ | |
| const int sentenceSize = 80; | |
| char sentence[sentenceSize]; | |
| int error = 0; | |
| /** | |
| Main hardware declaration | |
| **/ | |
| //AltSoftSerial gpsSerial; //GPS Module: 9 (TX) → Not in use , 8 (RX) Library. | |
| /** | |
| L298N Pin definitions | |
| **/ | |
| /** | |
| Other variables | |
| **/ | |
| int dt = 0; // Time interval | |
| unsigned long t; // Last time mark reference | |
| void setup() | |
| { | |
| Serial.begin(9600); // Start main Serial communication | |
| //gpsSerial.begin(9600); // Start the GPS Module | |
| } | |
| void loop() | |
| { | |
| static int i = 0; | |
| if (Serial.available()) | |
| { | |
| char ch = Serial.read(); | |
| if (ch != '\n' && i < sentenceSize) | |
| { | |
| sentence[i] = ch; | |
| i++; | |
| } | |
| else | |
| { | |
| sentence[i] = '\0'; | |
| i = 0; | |
| displayGPS(); | |
| } | |
| } | |
| Serial.flush(); | |
| } | |
| int incPulse(int val, int inc){ | |
| if( val + inc > 2000 ) | |
| return 1000 ; | |
| else | |
| return val + inc; | |
| } | |
| void displayGPS() | |
| { | |
| char field[40]; | |
| getField(field, 0); | |
| //Serial.print(field); | |
| if (strcmp(field, "$GPRMC") == 0) | |
| { | |
| Serial.print("Lat: "); | |
| getField(field, 3); // number | |
| Serial.print(field); | |
| getField(field, 4); // N/S | |
| Serial.print(field); | |
| Serial.print(" Long: "); | |
| getField(field, 5); // number | |
| Serial.print(field); | |
| getField(field, 6); // E/W | |
| Serial.println(field); | |
| } | |
| } | |
| void getField(char* buffer, int index) | |
| { | |
| int sentencePos = 0; | |
| int fieldPos = 0; | |
| int commaCount = 0; | |
| while (sentencePos < sentenceSize) | |
| { | |
| if (sentence[sentencePos] == ',') | |
| { | |
| commaCount ++; | |
| sentencePos ++; | |
| } | |
| if (commaCount == index) | |
| { | |
| buffer[fieldPos] = sentence[sentencePos]; | |
| fieldPos ++; | |
| } | |
| sentencePos ++; | |
| } | |
| buffer[fieldPos] = '\0'; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment