Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define I2C_ADDRESS 0x3C
- #include "SSD1306Ascii.h"
- #include "SSD1306AsciiAvrI2c.h"
- #include <TinyGPS++.h>
- #include <SoftwareSerial.h>
- #define ARDUINO_GPS_RX 8
- #define ARDUINO_GPS_TX 7
- #define GPS_BAUD 9600
- #define gpsPort ssGPS
- #define SerialMonitor Serial
- #define I2C_ADDRESS 0x3C
- TinyGPSPlus gps;
- SoftwareSerial ssGPS(ARDUINO_GPS_TX, ARDUINO_GPS_RX);
- SSD1306AsciiAvrI2c oled;
- int godz;
- void setup()
- {
- SerialMonitor.begin(9600);
- gpsPort.begin(GPS_BAUD);
- oled.begin(&Adafruit128x64, I2C_ADDRESS);
- oled.setFont(System5x7);
- oled.clear();
- }
- void loop()
- {
- // static const double LONDON_LAT = 51.508131, LONDON_LON = -0.128002;
- printGPSInfo();
- smartDelay(300);
- oled.setCursor(0, 0);
- }
- void printGPSInfo()
- {
- oled.print("Lat: "); oled.println(gps.location.lat(), 8);
- oled.print("Long: "); oled.println(gps.location.lng(), 8);
- oled.print("Date: "); printDate();
- oled.print("TimeGPS: "); printTimeRAW();
- oled.print("Time: "); printTime();
- oled.print("Sat: "); printSat();
- oled.print("Course: "); printCourse();
- oled.print("Speed: "); printSpeed();
- }
- static void smartDelay(unsigned long ms)
- {
- unsigned long start = millis();
- do
- {
- while (gpsPort.available())
- gps.encode(gpsPort.read());
- } while (millis() - start < ms);
- }
- void printDate()
- {
- oled.print(gps.date.day());
- oled.print("/");
- oled.print(gps.date.month());
- oled.print("/");
- oled.println(gps.date.year());
- }
- void printTimeRAW()
- {
- oled.print(gps.time.hour());
- oled.print(":");
- if (gps.time.minute() < 10) oled.print('0');
- oled.print(gps.time.minute());
- oled.print(":");
- if (gps.time.second() < 10) oled.print('0');
- oled.println(gps.time.second());
- }
- void printTime()
- {
- switch(gps.time.hour()){
- case 22:
- oled.print("00");
- oled.print(":");
- break;
- case 23:
- oled.print("01");
- oled.print(":");
- break;
- default:
- oled.print(gps.time.hour()+2);
- oled.print(":");
- break;
- }
- if (gps.time.minute() < 10) oled.print('0');
- oled.print(gps.time.minute());
- oled.print(":");
- if (gps.time.second() < 10) oled.print('0');
- oled.println(gps.time.second());
- }
- void printSat()
- {
- if (gps.satellites.value() < 10) oled.print('0');
- oled.println(gps.satellites.value());
- }
- void printCourse()
- {
- oled.println(gps.course.deg());
- }
- void printSpeed()
- {
- oled.print(gps.speed.kmph());
- oled.print("km/h");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement