Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ######## ######## ###### ########## ########## ###### ##########
- ## ## ## ## ## ## ## ## ## ##
- ## ## ## ## ## ## ## ##
- ## ###### ######## ###### ## ###### ###### ##
- ## ## ## ## ## ## ## ##
- ## ## ## ## ## ## ## ## ## ##
- ######## ## ###### ########## ## ########## ###### ##
- */
- // ####################
- // LIBRARIES
- // ####################
- #include <TinyGPS++.h>
- #include <SoftwareSerial.h>
- #include <ParallaxLCD.h>
- // ####################
- // CONFIGURATION
- // ####################
- #define ROWS 2
- #define COLS 16
- // ####################
- // HARDWARE
- // ####################
- static const int RXPin = 4, TXPin = 3;
- static const int GPSBaud = 9600;
- // ####################
- // GLOBALS
- // ####################
- // The TinyGPS++ object
- TinyGPSPlus gps;
- // The serial connection to the GPS device
- SoftwareSerial ss(RXPin, TXPin);
- // prepare the lcd object
- ParallaxLCD lcd(2,2,16);
- /*
- ########## ## ## ## ## ###### ########## ###### ###### ## ## ######
- ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
- ## ## ## #### ## ## ## ## ## ## #### ## ##
- ###### ## ## ## ## ## ## ## ## ## ## ## ## ## ######
- ## ## ## ## #### ## ## ## ## ## ## #### ##
- ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
- ## ###### ## ## ###### ## ###### ###### ## ## ######
- */
- // ####################
- // DISPLAYINFO
- // ####################
- void displayInfo() {
- if (not gps.time.isValid()) {
- continue;
- }
- if (gps.date.month() < 10) {
- lcd.at(0,2,gps.date.month());
- } else {
- lcd.at(0,1,gps.date.month());
- }
- lcd.at(0,3,"/");
- if (gps.date.day() < 10) {
- lcd.at(0,5,gps.date.day());
- } else {
- lcd.at(0,4,gps.date.day());
- }
- lcd.at(0,6,"/");
- lcd.at(0,7,gps.date.year());
- if (gps.time.hour() < 10) {
- lcd.at(1,4,gps.time.hour());
- } else {
- lcd.at(1,3,gps.time.hour());
- }
- lcd.at(1,5,":");
- if (gps.time.minute() < 10) {
- lcd.at(1,6,"0");
- lcd.at(1,7,gps.time.minute());
- } else {
- lcd.at(1,6,gps.time.minute());
- }
- lcd.at(1,8,":");
- if (gps.time.second() < 10) {
- lcd.at(1,9,"0");
- lcd.at(1,10,gps.time.second());
- } else {
- lcd.at(1,9,gps.time.second());
- }
- }
- /*
- ###### ########## ########## ## ## ########
- ## ## ## ## ## ## ## ##
- ## ## ## ## ## ## ##
- ###### ###### ## ## ## ########
- ## ## ## ## ## ##
- ## ## ## ## ## ## ##
- ###### ########## ## ###### ##
- */
- void setup () {
- Serial.begin(9600);
- lcd.setup();
- delay(1000);
- lcd.backLightOn();
- delay(1000);
- ss.begin(GPSBaud);
- }
- /*
- ## ###### ###### ########
- ## ## ## ## ## ## ##
- ## ## ## ## ## ## ##
- ## ## ## ## ## ########
- ## ## ## ## ## ##
- ## ## ## ## ## ##
- ########## ###### ###### ##
- */
- // This sketch displays information every time a new sentence is correctly encoded.
- void loop() {
- while (ss.available() > 0) {
- if (gps.encode(ss.read())) {
- displayInfo();
- }
- if (millis() > 5000 && gps.charsProcessed() < 10) {
- lcd.at(0,0,"No GPS detected: check wiring.");
- while(true);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement