Advertisement
Guest User

Untitled

a guest
Aug 29th, 2015
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.50 KB | None | 0 0
  1.  
  2. /*
  3. ######## ######## ###### ########## ########## ###### ##########
  4. ## ## ## ## ## ## ## ## ## ##
  5. ## ## ## ## ## ## ## ##
  6. ## ###### ######## ###### ## ###### ###### ##
  7. ## ## ## ## ## ## ## ##
  8. ## ## ## ## ## ## ## ## ## ##
  9. ######## ## ###### ########## ## ########## ###### ##
  10. */
  11.  
  12.  
  13.  
  14. // ####################
  15. // LIBRARIES
  16. // ####################
  17.  
  18. #include <TinyGPS++.h>
  19. #include <SoftwareSerial.h>
  20. #include <ParallaxLCD.h>
  21.  
  22.  
  23. // ####################
  24. // CONFIGURATION
  25. // ####################
  26.  
  27.  
  28. #define ROWS 2
  29. #define COLS 16
  30.  
  31.  
  32. // ####################
  33. // HARDWARE
  34. // ####################
  35.  
  36. static const int RXPin = 4, TXPin = 3;
  37. static const int GPSBaud = 9600;
  38.  
  39.  
  40. // ####################
  41. // GLOBALS
  42. // ####################
  43.  
  44. // The TinyGPS++ object
  45. TinyGPSPlus gps;
  46.  
  47. // The serial connection to the GPS device
  48. SoftwareSerial ss(RXPin, TXPin);
  49.  
  50. // prepare the lcd object
  51. ParallaxLCD lcd(2,2,16);
  52.  
  53.  
  54.  
  55.  
  56. /*
  57. ########## ## ## ## ## ###### ########## ###### ###### ## ## ######
  58. ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
  59. ## ## ## #### ## ## ## ## ## ## #### ## ##
  60. ###### ## ## ## ## ## ## ## ## ## ## ## ## ## ######
  61. ## ## ## ## #### ## ## ## ## ## ## #### ##
  62. ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
  63. ## ###### ## ## ###### ## ###### ###### ## ## ######
  64. */
  65.  
  66.  
  67.  
  68. // ####################
  69. // DISPLAYINFO
  70. // ####################
  71.  
  72. void displayInfo() {
  73.  
  74. if (not gps.time.isValid()) {
  75. continue;
  76. }
  77.  
  78. if (gps.date.month() < 10) {
  79. lcd.at(0,2,gps.date.month());
  80. } else {
  81. lcd.at(0,1,gps.date.month());
  82. }
  83. lcd.at(0,3,"/");
  84.  
  85. if (gps.date.day() < 10) {
  86. lcd.at(0,5,gps.date.day());
  87. } else {
  88. lcd.at(0,4,gps.date.day());
  89. }
  90. lcd.at(0,6,"/");
  91.  
  92. lcd.at(0,7,gps.date.year());
  93. if (gps.time.hour() < 10) {
  94. lcd.at(1,4,gps.time.hour());
  95. } else {
  96. lcd.at(1,3,gps.time.hour());
  97. }
  98. lcd.at(1,5,":");
  99.  
  100. if (gps.time.minute() < 10) {
  101. lcd.at(1,6,"0");
  102. lcd.at(1,7,gps.time.minute());
  103. } else {
  104. lcd.at(1,6,gps.time.minute());
  105. }
  106. lcd.at(1,8,":");
  107.  
  108. if (gps.time.second() < 10) {
  109. lcd.at(1,9,"0");
  110. lcd.at(1,10,gps.time.second());
  111. } else {
  112. lcd.at(1,9,gps.time.second());
  113. }
  114.  
  115. }
  116.  
  117.  
  118.  
  119. /*
  120. ###### ########## ########## ## ## ########
  121. ## ## ## ## ## ## ## ##
  122. ## ## ## ## ## ## ##
  123. ###### ###### ## ## ## ########
  124. ## ## ## ## ## ##
  125. ## ## ## ## ## ## ##
  126. ###### ########## ## ###### ##
  127. */
  128.  
  129. void setup () {
  130. Serial.begin(9600);
  131. lcd.setup();
  132. delay(1000);
  133. lcd.backLightOn();
  134. delay(1000);
  135. ss.begin(GPSBaud);
  136. }
  137.  
  138.  
  139.  
  140. /*
  141. ## ###### ###### ########
  142. ## ## ## ## ## ## ##
  143. ## ## ## ## ## ## ##
  144. ## ## ## ## ## ########
  145. ## ## ## ## ## ##
  146. ## ## ## ## ## ##
  147. ########## ###### ###### ##
  148. */
  149.  
  150. // This sketch displays information every time a new sentence is correctly encoded.
  151.  
  152. void loop() {
  153. while (ss.available() > 0) {
  154. if (gps.encode(ss.read())) {
  155. displayInfo();
  156. }
  157. if (millis() > 5000 && gps.charsProcessed() < 10) {
  158. lcd.at(0,0,"No GPS detected: check wiring.");
  159. while(true);
  160. }
  161. }
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement