В общем пиликает 3 дня нормально на 4 день ровно в 00.00.00 часов,начинает пиликать 23 секунды.Потом через 3 дня,опять в 00.00.00 часов пиликает 23 секунды.Потом через 2 дня,опять в 00.00.00 часов пиликает 23 секунды.Потом через 1 день,опять в 00.00.00 часов пиликает 23 секунды.Потом снова Повторяется.С начала.И так по кругу.
#include <TinyGPS++.h> // include TinyGPS++ library
#include <TimeLib.h> // include Time library
#include <SoftwareSerial.h> // include Software serial library
#define _LCD_TYPE 1
#include <LCD_1602_RUS_ALL.h>
int pinBF = 8;
TinyGPSPlus gps;
#define S_RX 4 // define software serial RX pin
#define S_TX 3 // define software serial TX pin
SoftwareSerial SoftSerial(S_RX, S_TX); // configure SoftSerial library
// initialise the LCD 1602 I2C
LCD_1602_RUS <LiquidCrystal_I2C> lcd(0x27, 16, 2);
#define time_offset 18000 // define a clock offset of 18000 seconds (5 hours) ==> UTC + 5
// variable definitions
char Time[] = "00:00:00";
char Date[] = "00-00-2000";
byte last_second, Second, Minute, Hour, Day, Month;
int Year;
unsigned long last_time = 0; //вот эта переменная
void setup(void)
{
SoftSerial.begin(9600); // initialize software serial at 9600 baud
lcd.init(); //инициализация дисплея i2c
lcd.backlight();
lcd.setCursor(2, 0); // move LCD cursor to column 2, row 0
lcd.print("CLOCK");
lcd.setCursor(0, 1); // move LCD cursor to column 0, row 1
lcd.print("CLOCK UTC+5");
delay(2000);
lcd.clear();
pinMode(pinBF, OUTPUT);
}
void loop()
{
if ((millis() - last_time) > 640)
{
if ((gps.time.minute() == 0 ) && (gps.time.second() == 0 ))
{
const byte per = 119;
noInterrupts();
for (int i = 512; i--; i > 0)
{
digitalWrite(pinBF, 1);
delayMicroseconds(per);
digitalWrite(pinBF, 0);
delayMicroseconds(per);
}
delay(25000);
for (int i = 512; i--; i > 0)
{
digitalWrite(pinBF, 1);
delayMicroseconds(per);
digitalWrite(pinBF, 0);
delayMicroseconds(per);
}
interrupts ();
}
last_time = millis();
}
while (SoftSerial.available() > 0)
{
if (gps.encode(SoftSerial.read()))
{
// get time from GPS module
if (gps.time.isValid())
{
Minute = gps.time.minute();
Second = gps.time.second();
Hour = gps.time.hour();
}
// get date drom GPS module
if (gps.date.isValid())
{
Day = gps.date.day();
Month = gps.date.month();
Year = gps.date.year();
}
if (last_second != gps.time.second()) // if time has changed
{
last_second = gps.time.second();
// set current UTC time
setTime(Hour, Minute, Second, Day, Month, Year);
// add the offset to get local time
adjustTime(time_offset);
// update time array
Time[0] = hour() / 10 + '0';
Time[1] = hour() % 10 + '0';
Time[3] = minute() / 10 + '0';
Time[4] = minute() % 10 + '0';
Time[6] = second() / 10 + '0';
Time[7] = second() % 10 + '0';
// update date array
Date[0] = day() / 10 + '0';
Date[1] = day() % 10 + '0';
Date[3] = month() / 10 + '0';
Date[4] = month() % 10 + '0';
Date[8] = (year() / 10) % 10 + '0';
Date[9] = year() % 10 + '0';
// print time & date
print_wday(weekday()); // print day of the week
lcd.setCursor(0, 0); // move cursor to column 0 row 1
lcd.print(Time); // print time (HH:MM:SS)
lcd.setCursor(0, 1); // move cursor to column 0 row 0
lcd.print(Date); // print date (DD-MM-YYYY)
lcd.setCursor(11, 1); // move cursor to column 11 row 1
lcd.print("UTC+5"); // print text
}
}
}
}
// function for displaying day of the week
void print_wday(byte wday)
{
lcd.setCursor(9, 0); // move cursor to column 9, row 0
switch (wday)
{
case 1: lcd.print("ВОСКРЕС"); break;
case 2: lcd.print("ПОНЕДЕЛ"); break;
case 3: lcd.print("ВТОРНИК"); break;
case 4: lcd.print("СРЕДА "); break;
case 5: lcd.print("ЧЕТВЕРГ"); break;
case 6: lcd.print("ПЯТНИЦА"); break;
default: lcd.print("СУББОТА");
}
}
Исправленный Скетч.
#include <TinyGPS++.h> // include TinyGPS++ library
#include <TimeLib.h> // include Time library
#include <SoftwareSerial.h> // include Software serial library
#define _LCD_TYPE 1
#include <LCD_1602_RUS_ALL.h>
int pinBF = 8;
TinyGPSPlus gps;
#define S_RX 4 // define software serial RX pin
#define S_TX 3 // define software serial TX pin
SoftwareSerial SoftSerial(S_RX, S_TX); // configure SoftSerial library
// initialise the LCD 1602 I2C
LCD_1602_RUS <LiquidCrystal_I2C> lcd(0x27, 16, 2);
#define time_offset 18000 // define a clock offset of 18000 seconds (5 hours) ==> UTC + 5
// variable definitions
char Time[] = "00:00:00";
char Date[] = "00-00-2000";
byte last_second, Second, Minute, Hour, Day, Month, flag = 1;
int Year;
unsigned long last_time = 0; //вот эта переменная
void setup(void)
{
SoftSerial.begin(9600); // initialize software serial at 9600 baud
lcd.init(); //инициализация дисплея i2c
lcd.backlight();
lcd.setCursor(2, 0); // move LCD cursor to column 2, row 0
lcd.print("CLOCK");
lcd.setCursor(0, 1); // move LCD cursor to column 0, row 1
lcd.print("CLOCK UTC+5");
delay(2000);
lcd.clear();
pinMode(pinBF, OUTPUT);
}
void loop()
{
if ((millis() - last_time) > 640)
{
if ( gps.time.minute() != 0 )
{
flag = 1; // новое
}
if ((gps.time.minute() == 0 ) && (gps.time.second() == 0 ) && flag) // новое
{
const byte per = 119;
noInterrupts();
for (int i = 512; i--; i > 0)
{
digitalWrite(pinBF, 1);
delayMicroseconds(per);
digitalWrite(pinBF, 0);
delayMicroseconds(per);
}
delay(25000);
for (int i = 512; i--; i > 0)
{
digitalWrite(pinBF, 1);
delayMicroseconds(per);
digitalWrite(pinBF, 0);
delayMicroseconds(per);
}
interrupts ();
flag = 0; //новое
}
last_time = millis();
}
while (SoftSerial.available() > 0)
{
if (gps.encode(SoftSerial.read()))
{
// get time from GPS module
if (gps.time.isValid())
{
Minute = gps.time.minute();
Second = gps.time.second();
Hour = gps.time.hour();
}
// get date drom GPS module
if (gps.date.isValid())
{
Day = gps.date.day();
Month = gps.date.month();
Year = gps.date.year();
}
if (last_second != gps.time.second()) // if time has changed
{
last_second = gps.time.second();
// set current UTC time
setTime(Hour, Minute, Second, Day, Month, Year);
// add the offset to get local time
adjustTime(time_offset);
// update time array
Time[0] = hour() / 10 + '0';
Time[1] = hour() % 10 + '0';
Time[3] = minute() / 10 + '0';
Time[4] = minute() % 10 + '0';
Time[6] = second() / 10 + '0';
Time[7] = second() % 10 + '0';
// update date array
Date[0] = day() / 10 + '0';
Date[1] = day() % 10 + '0';
Date[3] = month() / 10 + '0';
Date[4] = month() % 10 + '0';
Date[8] = (year() / 10) % 10 + '0';
Date[9] = year() % 10 + '0';
// print time & date
print_wday(weekday()); // print day of the week
lcd.setCursor(0, 0); // move cursor to column 0 row 1
lcd.print(Time); // print time (HH:MM:SS)
lcd.setCursor(0, 1); // move cursor to column 0 row 0
lcd.print(Date); // print date (DD-MM-YYYY)
lcd.setCursor(11, 1); // move cursor to column 11 row 1
lcd.print("UTC+5"); // print text
}
}
}
}
// function for displaying day of the week
void print_wday(byte wday)
{
lcd.setCursor(9, 0); // move cursor to column 9, row 0
switch (wday)
{
case 1: lcd.print("ВОСКРЕС"); break;
case 2: lcd.print("ПОНЕДЕЛ"); break;
case 3: lcd.print("ВТОРНИК"); break;
case 4: lcd.print("СРЕДА "); break;
case 5: lcd.print("ЧЕТВЕРГ"); break;
case 6: lcd.print("ПЯТНИЦА"); break;
default: lcd.print("СУББОТА");
}
}