#include <LiquidCrystal_I2C.h>// set the LCD number of columns and rows
int lcdColumns = 16;
int lcdRows = 2;
// set LCD address, number of columns and rows
// if you don't know your display address, run an I2C scanner sketch
LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);
//---------------------serial print--------------------------------------
long days=0;
long hours=0;
long mins=0;
long secs=0;
long currentmillis=0;
unsigned long time1;
unsigned long last_time;
unsigned long duration;
int reset;
void setup(){
Serial.begin(9600);
last_time = 0;
reset = 0;
//Serial.print(min());
// initialize LCD
lcd.init();
// turn on LCD backlight
lcd.backlight();
}
void loop(){
time1 = millis();
GetTimeRunning();
delay(1000);
if (days>0) // days will displayed only if value is greater than zero
{
Serial.print(days);
Serial.print(" days and: ");
}
Serial.print(hours);
Serial.print(" hours: ");
Serial.print(mins);
Serial.print(" minutes: ");
Serial.print(secs);
Serial.println(" Seconds.");
}
void GetTimeRunning()
{
currentmillis= millis();
secs = currentmillis/1000; //convect milliseconds to seconds
mins=secs/60; //convert seconds to minutes
hours=mins/60; //convert minutes to hours
days=hours/24; //convert hours to days
//secs=secs-(mins*60); //subtract the coverted seconds to minutes in order to display 59 secs max
//mins=mins-(hours*60); //subtract the coverted minutes to hours in order to display 59 minutes max
//hours=hours-(days*24); //subtract the coverted hours to days in order to display 23 hours max
//Display results
secs %= 60; //remainder when divided by 60
mins %= 60; //remainder when divided by 60
hours %= 24; //remainder when divided by 24
//--------tampilkan di LCD-----------------------------
// JAM
lcd.setCursor(0, 1);
lcd.print(hours);
// DETIK
lcd.setCursor(6, 1);
// print message
lcd.print(secs);
//MENIT
lcd.setCursor(4, 1);
lcd.print(mins);
}