Guest User

ARDUINO + GPS = INDICATOR LIMIT AREA

a guest
Oct 9th, 2014
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.52 KB | None | 0 0
  1. #include <string.h>
  2. #include <ctype.h>
  3. #include <LiquidCrystal.h>
  4.  int ledPin1= 10; // LED test pin
  5.  int ledPin2= 9; //LED warning limit
  6.  int ledPin3= 8; //LED warning over limit
  7.  int rxPin = 0;                    // RX PIN
  8.  int txPin = 1;                    // TX TX
  9.  int rx_val =0 ;
  10.  int byteGPS=-1;
  11.  char linea[300] = "";
  12.  char comandoGPR[7] = "$GPRMC";
  13.  int cont=0;
  14.  int bien=0;
  15.  int conta=0;
  16.  int indices[13];
  17.  LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
  18.  void setup() {
  19.    pinMode(10,OUTPUT);       // Initialize LED pin
  20.    pinMode(9, OUTPUT);
  21.    pinMode(8, OUTPUT);
  22.    pinMode(rxPin, INPUT);
  23.    pinMode(txPin, OUTPUT);
  24.    lcd.begin(16,2);
  25.    lcd.setCursor(0,0);
  26.    lcd.print("Lat:");
  27.   //lcd.setCursor(0,1);
  28.   //lcd.print("Long:");
  29.    Serial.begin(4800);
  30.    for (int i=0;i<300;i++){       // Initialize a buffer for received data
  31.      linea[i]=' ';
  32.    }  
  33.  }
  34.  void loop() {
  35.    digitalWrite(10,HIGH); //indikator  runing data reciver
  36.    byteGPS=Serial.read();    // Read a byte of the serial port
  37.    //lcd.write(Serial.read()); // TAMBAHAN
  38.    if (byteGPS == -1) {           // See if the port is empty yet
  39.      delay(100);
  40.    } else {
  41.      // note: there is a potential buffer overflow here!
  42.      linea[conta]=byteGPS;        // If there is serial port data, it is put in the buffer
  43.      conta++;                      
  44.      Serial.write(byteGPS);
  45.      
  46.      if (byteGPS==13){            // If the received byte is = to 13, end of transmission
  47.        // note: the actual end of transmission is <CR><LF> (i.e. 0x13 0x10)
  48.        digitalWrite(10, LOW);
  49.        cont=0;
  50.        bien=0;
  51.        // The following for loop starts at 1, because this code is clowny and the first byte is the <LF> (0x10) from the previous transmission.
  52.        for (int i=1;i<7;i++){     // Verifies if the received command starts with $GPR
  53.          if (linea[i]==comandoGPR[i-1]){
  54.            bien++;
  55.          }
  56.        }
  57.      
  58.        if(bien==6){               // If yes, continue and process the data
  59.          for (int i=0;i<300;i++){
  60.            if (linea[i]==','){    // check for the position of the  "," separator
  61.              // note: again, there is a potential buffer overflow here!
  62.              indices[cont]=i;
  63.              cont++;
  64.            }
  65.            if (linea[i]=='*'){    // ... and the "*"
  66.              indices[12]=i;
  67.              cont++;
  68.            }
  69.          }
  70.          Serial.println("");      // ... and write to the serial port
  71.          Serial.println("");
  72.          Serial.println("---------------");
  73.          for (int i=0;i<12;i++){
  74.            switch(i){
  75.              
  76.              case 0 :Serial.print("Time in UTC (HhMmSs): "); break;
  77.              case 1 :Serial.print("Status (A=OK,V=KO): ");break;
  78.              case 2 :Serial.print("Latitude: ");break;
  79.              case 3 :Serial.print("Direction (N/S): ");break;
  80.              case 4 :Serial.print("Longitude: ");break;
  81.              case 5 :Serial.print("Direction (E/W): ");break;
  82.              case 6 :Serial.print("Velocity in knots: ");break;
  83.              case 7 :Serial.print("Heading in degrees: ");break;
  84.              case 8 :Serial.print("Date UTC (DdMmAa): ");break;
  85.              case 9 :Serial.print("Magnetic degrees: ");break;
  86.              case 10 :Serial.print("(E/W): ");break;
  87.              case 11 :Serial.print("Mode: ");break;
  88.              case 12 :Serial.print("Checksum: ");break;
  89.            }
  90.           for (int j=indices[i];j<(indices[i+1]-1);j++){
  91.              Serial.print(linea[j+1]);                
  92.              lcd.print(linea[j+15]);
  93.              delay(0);
  94.              
  95.            // lcd.setCursor(5,1);   // set cursor valLong :                          
  96.            //  lcd.print(linea[j+35]);
  97.            //  delay(0);
  98.                      
  99.             if (linea[j+21]>4 ){
  100.              digitalWrite(9, HIGH); //indikator warning limit
  101.              }else{
  102.              digitalWrite(9, LOW);
  103.             // delay(100);
  104.            
  105.              if (linea[j+21]>9 ){
  106.              digitalWrite(8, HIGH); //indikator over limit
  107.              }else{
  108.              digitalWrite(8, LOW);
  109.             // delay(100);
  110.            
  111.              }
  112.                }
  113.    
  114.            }
  115.            
  116.            Serial.println("");
  117.          }
  118.          Serial.println("---------------");
  119.        }
  120.        conta=0;                    // Reset the buffer
  121.        for (int i=0;i<300;i++){    //  
  122.          linea[i]=' ';            
  123.        }                
  124.      }
  125.    }
  126.            lcd.setCursor(4,0); // set cursor val Lat :  
  127.            
  128.  }
Advertisement
Add Comment
Please, Sign In to add comment