Hi,
I am working on a egg incubator project, and i am trying to add an "elapsaed time counter", my problem is that i cant figure out how to print the elapsed time on my display, i think i have to use string; and float; i just cant figure out how to implement them.
If there is an easier way i would very much like to hear about it.
My code is posted underneath of here.
Thank you in advance.
//Morten
//DISPLAY
#define oledPin 8
#include <AXE133Y.h> //Inkludere Displayet
AXE133Y OLED = AXE133Y(oledPin);
long day = 86400000; // 86400000 milliseconds in a day
long hour = 3600000; // 3600000 milliseconds in an hour
long minute = 60000; // 60000 milliseconds in a minute
long second = 1000; // 1000 milliseconds in a second
void setup(){
Serial.begin (9600);
}
void loop(){
time();
delay(1000);
}
void time(){
long timeNow = millis();
int days = timeNow / day ; //number of days
int hours = (timeNow % day) / hour; //the remainder from days division (in milliseconds) divided by hours, this gives the full hours
int minutes = ((timeNow % day) % hour) / minute ; //and so on...
int seconds = (((timeNow % day) % hour) % minute) / second;
// digital clock display of current time
Serial.print(days,DEC);
printDigits(hours);
printDigits(minutes);
printDigits(seconds);
Serial.println();
}
void printDigits(byte digits){
// utility function for digital clock display: prints colon and leading 0
Serial.print(":");
if(digits < 10)
Serial.print('0');
Serial.print(digits,DEC);
}