//TM1637 GPS clock
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include "SevenSegmentTM1637.h"
#include "SevenSegmentExtended.h"
static const int RXPin = 5, TXPin = 6; // TX -> D4, RX -> D3
static const uint32_t GPSBaud = 9600;
TinyGPSPlus gps;
SoftwareSerial ss(RXPin, TXPin);
const byte PIN_CLK = 2; // define CLK pin (any digital pin)
const byte PIN_DIO = 3; // define DIO pin (any digital pin)
SevenSegmentExtended display(PIN_CLK, PIN_DIO);
int Satellites = 12;
int hours = 0;
int minutes = 0;
int wasMinute = 99; // used for blanking leading zero
int DSTEST = 8;//GMT+8
int TwelveTwentyFour = 24;
void setup() {
Serial.begin(115200);
ss.begin(GPSBaud);
display.begin(); // initializes the display
display.setBacklight(100); // set the brightness to 100 %
delay(1000); // wait 1000 ms
hours = 99;
minutes = 99;
display.printTime(hours, minutes, true); // display time
pinMode(Satellites, INPUT_PULLUP);
delay(1000);
}
void loop() {
while (ss.available() > 0)
if (gps.encode(ss.read()))
displayInfo();
if (millis() > 5000 && gps.charsProcessed() < 10) {
Serial.println(F("No GPS detected: check wiring."));
while (true);
}
}
void displayInfo() {
int SW5 = digitalRead(Satellites);
if (SW5 == LOW) {
display.print("Sat=");
delay(500);
display.clear();
int temp = gps.satellites.value();
Serial.print("temp = ");
Serial.println(temp);
display.print(gps.satellites.value());
Serial.print("Satellites Seen = ");
Serial.println(gps.satellites.value());
delay(1000);
}
Serial.print(F("Location: "));
if (gps.location.isValid()) {
Serial.print(gps.location.lat(), 6);
Serial.print(F(","));
Serial.print(gps.location.lng(), 6);
}
else
{
Serial.print(F("INVALID"));
}
Serial.print(F(" Date/Time: "));
if (gps.date.isValid()) {
Serial.print(gps.date.month());
Serial.print(F("/"));
Serial.print(gps.date.day());
Serial.print(F("/"));
Serial.print(gps.date.year());
}
else
{
Serial.print(F("INVALID"));
}
Serial.print(F(" "));
if (gps.time.isValid()) {
if (gps.time.hour() < 10) Serial.print(F("0"));
Serial.print(gps.time.hour() + 9 ); // time ZONE mod
Serial.print(F(":"));
if (gps.time.minute() < 10) Serial.print(F("0"));
Serial.print(gps.time.minute());
Serial.print(F(":"));
if (gps.time.second() < 10) Serial.print(F("0"));
Serial.print(gps.time.second());
Serial.print(F("."));
if (gps.time.centisecond() < 10) Serial.print(F("0"));
Serial.print(gps.time.centisecond());
/////////////////To Clock LED Display/////////////////////////////
int hours = gps.time.hour();
Serial.print(" DST = ");
Serial.print(DSTEST);
int timezonehr = DSTEST;
hours = hours + timezonehr;
if (hours > TwelveTwentyFour - 1) {
hours = hours - TwelveTwentyFour;
if (hours == 0) hours = 12; // make sure shows 12 at noon
}
else {
if (hours < 0) {
hours = hours + TwelveTwentyFour;
}
}
/////////////////To Clock LED Display/////////////////////////////
int minutes = gps.time.minute();
if (minutes != wasMinute) {
Serial.print("Hours just before sent to LED ");
Serial.println(hours);
display.printTime(hours, minutes, false); // display time
if ( hours <= 9) {
display.print(" ");
}
wasMinute = minutes;
}
}
else
{
Serial.print(F("INVALID"));
}
Serial.println();
}
Do you have a question ?
I suspect you're having problems processing gps text strings. Please read:
No I just want to share my code to you
Was this the subject of a previous thread? If so, then please post it there, as a followup.
Otherwise, perhaps it should go to showcase, though for that it should have at minimum a complete schematic, and textual description.