Advertisement
Guest User

Untitled

a guest
Apr 4th, 2012
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1. /*
  2. * Simple sketch that will output the serial feed of GPS
  3.  */
  4. #include <SoftwareSerial.h>
  5. const unsigned int MAX_INPUT = 150;
  6. const unsigned int NB_LINES = 10;
  7.  
  8. // Software serial port.
  9. // only receive on pin 3
  10. SoftwareSerial ss(3, 2);
  11.  
  12. void setup()
  13. {
  14.   Serial.begin(115200); // serial to PC
  15.   Serial.println("Waiting for GPS...");
  16.   ss.begin(38400); // start serial port for the GPS
  17.   ss.listen(); // listen on this software serial port, should not be necessary with only one software port.
  18. }
  19.  
  20. void loop()
  21. {
  22.   static char line[NB_LINES][MAX_INPUT];
  23.   static unsigned int pos=0;
  24.   static unsigned int linenb=0;
  25.  
  26.   if(ss.available()>0)
  27.   {
  28.     // read on hardware serial port
  29.     //char c=Serial.read();
  30.     // read on software serial port
  31.     char c=ss.read();
  32.     switch(c)
  33.     {
  34.     case '\n': // end of line
  35.       line[linenb++][pos]=0; // terminate with null byte
  36.       pos=0;
  37.       if(linenb>=NB_LINES)
  38.       {
  39.         Serial.println("");
  40.         Serial.println("Bloc");
  41.         for(int i=0;i<NB_LINES;i++)Serial.println(line[i]);
  42.         linenb=0;
  43.       }
  44.       break;
  45.     default:
  46.       if (pos < (MAX_INPUT - 1))
  47.         line [linenb][pos++] = c;
  48.       break;
  49.     }
  50.   }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement