Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. #define I2C_ADDRESS 0x3C
  2. #include "SSD1306Ascii.h"
  3. #include "SSD1306AsciiAvrI2c.h"
  4. #include <TinyGPS++.h>
  5. #include <SoftwareSerial.h>
  6. #define ARDUINO_GPS_RX 8
  7. #define ARDUINO_GPS_TX 7
  8. #define GPS_BAUD 9600
  9. #define gpsPort ssGPS
  10. #define SerialMonitor Serial
  11. #define I2C_ADDRESS 0x3C
  12. TinyGPSPlus gps;
  13. SoftwareSerial ssGPS(ARDUINO_GPS_TX, ARDUINO_GPS_RX);
  14. SSD1306AsciiAvrI2c oled;
  15. int godz;
  16.  
  17. void setup()
  18. {
  19. SerialMonitor.begin(9600);
  20. gpsPort.begin(GPS_BAUD);
  21. oled.begin(&Adafruit128x64, I2C_ADDRESS);
  22. oled.setFont(System5x7);
  23. oled.clear();
  24. }
  25.  
  26. void loop()
  27. {
  28.  
  29. // static const double LONDON_LAT = 51.508131, LONDON_LON = -0.128002;
  30.  
  31. printGPSInfo();
  32. smartDelay(300);
  33. oled.setCursor(0, 0);
  34.  
  35. }
  36.  
  37. void printGPSInfo()
  38. {
  39.  
  40. oled.print("Lat: "); oled.println(gps.location.lat(), 8);
  41. oled.print("Long: "); oled.println(gps.location.lng(), 8);
  42. oled.print("Date: "); printDate();
  43. oled.print("TimeGPS: "); printTimeRAW();
  44. oled.print("Time: "); printTime();
  45. oled.print("Sat: "); printSat();
  46. oled.print("Course: "); printCourse();
  47. oled.print("Speed: "); printSpeed();
  48.  
  49. }
  50.  
  51.  
  52. static void smartDelay(unsigned long ms)
  53. {
  54. unsigned long start = millis();
  55. do
  56. {
  57.  
  58. while (gpsPort.available())
  59. gps.encode(gpsPort.read());
  60. } while (millis() - start < ms);
  61. }
  62.  
  63.  
  64. void printDate()
  65. {
  66.  
  67. oled.print(gps.date.day());
  68. oled.print("/");
  69. oled.print(gps.date.month());
  70. oled.print("/");
  71. oled.println(gps.date.year());
  72. }
  73.  
  74. void printTimeRAW()
  75. {
  76.  
  77. oled.print(gps.time.hour());
  78. oled.print(":");
  79. if (gps.time.minute() < 10) oled.print('0');
  80. oled.print(gps.time.minute());
  81. oled.print(":");
  82. if (gps.time.second() < 10) oled.print('0');
  83. oled.println(gps.time.second());
  84. }
  85.  
  86. void printTime()
  87. {
  88. switch(gps.time.hour()){
  89. case 22:
  90. oled.print("00");
  91. oled.print(":");
  92. break;
  93.  
  94.  
  95. case 23:
  96. oled.print("01");
  97. oled.print(":");
  98. break;
  99.  
  100. default:
  101. oled.print(gps.time.hour()+2);
  102. oled.print(":");
  103. break;
  104. }
  105.  
  106.  
  107. if (gps.time.minute() < 10) oled.print('0');
  108. oled.print(gps.time.minute());
  109. oled.print(":");
  110. if (gps.time.second() < 10) oled.print('0');
  111. oled.println(gps.time.second());
  112. }
  113.  
  114. void printSat()
  115. {
  116. if (gps.satellites.value() < 10) oled.print('0');
  117. oled.println(gps.satellites.value());
  118. }
  119.  
  120. void printCourse()
  121. {
  122. oled.println(gps.course.deg());
  123. }
  124.  
  125. void printSpeed()
  126. {
  127. oled.print(gps.speed.kmph());
  128. oled.print("km/h");
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement