Display date for GPS Clock on MAX7219

Hello Newbie here!
I have a school project to display accurate clock using GPS. The clock is now fine. Need your help to modify the code to display date alternately with time.

Thanks!

Parts used:
Arduino Uno
Dot Matrix MAX7219 32X8 (8x8x4)
Ublox Neo-6M GPS

Here is the code:

#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <Adafruit_GFX.h>
#include <Max72xxPanel.h>
TinyGPSPlus tinyGPS;
#define GPSBaud 9600
#define ARDUINO_GPS_RX A1
#define ARDUINO_GPS_TX A0
SoftwareSerial ssGPS(ARDUINO_GPS_TX, ARDUINO_GPS_RX);
#define gpsPort ssGPS
#define SerialMonitor Serial
const byte PIN_CLK = 13;
const byte PIN_DIO = 11;
int pinCS = 10;
int numberOfHorizontalDisplays = 4; //total number of 8x8 matrix
int numberOfVerticalDisplays   = 1;
int wait = 70;
int spacer = 1;
int Y0 = 0;
int PHT;
int width  = 5 + spacer;
char time_value[20];
String s;
Max72xxPanel matrix = Max72xxPanel(pinCS, numberOfHorizontalDisplays, numberOfVerticalDisplays);

void setup()
{
  gpsPort.begin(GPSBaud);
  SerialMonitor.begin(9600);
  matrix.setIntensity(0);
  matrix.setPosition(0, 0, 0) ; 
  matrix.setPosition(1, 1, 0) ;
  matrix.setPosition(2, 2, 0) ;
  matrix.setPosition(3, 3, 0) ;
  matrix.setRotation(0, 1); 
  matrix.setRotation(1, 1);
  matrix.setRotation(2, 1); 
  matrix.setRotation(3, 1); 
  delay(500);
}
void loop()
{
  displayInfo();
  smartDelay(1000); 
}
void displayInfo()
{
  SerialMonitor.print("Latitude: "); SerialMonitor.println(tinyGPS.location.lat(), 6);
  SerialMonitor.print("Longitude: "); SerialMonitor.println(tinyGPS.location.lng(), 6);
  SerialMonitor.print("Altitude: "); SerialMonitor.println(tinyGPS.altitude.feet());
  SerialMonitor.print("Course: "); SerialMonitor.println(tinyGPS.course.deg());
  SerialMonitor.print("Speed: "); SerialMonitor.println(tinyGPS.speed.mph());
  SerialMonitor.print("Date: "); displayDate();
  SerialMonitor.print("Time: "); displayTime();
  SerialMonitor.print("Satellite: "); SerialMonitor.println(tinyGPS.satellites.value());
  SerialMonitor.println();
  PHT = tinyGPS.time.hour() +8; //Display Manila Time
  if( PHT >= 24 ) PHT = PHT - 24;
  s=String(PHT);
  if( s.length() == 1 )
  {
    s = " " + s;
    time_value[0]= s.charAt(0);
    time_value[1]= s.charAt(1);
  }
  else
  {
    time_value[0]= s.charAt(0);
    time_value[1]= s.charAt(1);
  } 
  s=String(tinyGPS.time.minute() );
  if( s.length() == 1 )
  {
    s = "0" + s;
    time_value[3]= s.charAt(0);
    time_value[4]= s.charAt(1);
  }
  else
  {
  time_value[3]= s.charAt(0);
  time_value[4]= s.charAt(1);
  }
  matrix.fillScreen(LOW);
  matrix.drawChar( 2, Y0, time_value[0], HIGH,LOW,1);
  matrix.drawChar( 8, Y0, time_value[1], HIGH,LOW,1);
  matrix.drawChar(20, Y0, time_value[3], HIGH,LOW,1);
  matrix.drawChar(26, Y0, time_value[4], HIGH,LOW,1);
  matrix.write();
  delay(1000); 
  matrix.drawChar(14,  0, 58, HIGH,LOW,1);
  matrix.write();
}
static void smartDelay(unsigned long ms)
{
  unsigned long start = millis();
  do
  {
    while (gpsPort.available())
      tinyGPS.encode(gpsPort.read());
      } while (millis() - start < ms);
}
void displayDate()
{
  SerialMonitor.print(tinyGPS.date.month());
  SerialMonitor.print("/");
  SerialMonitor.print(tinyGPS.date.day());
  SerialMonitor.print("/");
  SerialMonitor.println(tinyGPS.date.year());
}
void displayTime()
{
  SerialMonitor.print(tinyGPS.time.hour()+8);
  SerialMonitor.print(":");
  if (tinyGPS.time.minute() < 10) SerialMonitor.print('0');
    SerialMonitor.print(tinyGPS.time.minute());
    SerialMonitor.print(":");
  if (tinyGPS.time.second() < 10) SerialMonitor.print('0');
    SerialMonitor.println(tinyGPS.time.second());
}

Use a flag for showing time or date. Switch the flag at the interval You want.

To get the date right requires thought. You will really need to think this through.

What happens to the date if the hours are greater than 24 ? Did you think about that?

You are the third person this month to ask for help with showing the correct date on a GPS-based clock. What research have you done to see if there already exist solutions?

Also, I would get rid of the capital-S Strings if I were you. You don't need them. There are easier ways to convert a small number to ASCII digits.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.