Go Down

Topic: How to count time and put it in an SD card (Read 145 times)previous topic - next topic

Cassiusbab

Jun 13, 2018, 04:09 pm
Hello everybody !

My project consists basicly on detecting when a light is on and counting how many hours, minutes, seconds it is on. At the end,the SD card has to show how many hours in total it has been on.
I tried to uses millis() and each time its 1000, seconds will increment and same for minutes and same for hours, but it didn't work.
I also had problems putting the data ( in my case hours) on the SD card. Indeed, I can not do it in void loop since i want one data that has to increment.
Could you please give me some information that would save this project :p ?
Thanks

teunman

#1
Jun 13, 2018, 04:33 pm
Hi cassisubab,

Unfortunately without any code or idea of the setup you are using we cannot help. Please read the "how to post on this forum" post and provide us with some code. Maybe then we can help.

Grumpy_Mike

#2
Jun 13, 2018, 05:41 pm
Quote
Indeed, I can not do it in void loop since i want one data that has to increment.
No it is called the loop function, void is simply the type of variable the function returns, it is not part of the name.
And No you can do it in the loop function, so post what code you have and try and explain better what you are trying to do.

dave-in-nj

#3
Jun 13, 2018, 07:53 pm
this may be garbage, doing this on lunch...
you have to set the variables.
this is NOT code, this is just a general suggestion.

=========================

if (ONflag == LOW){     // only low when the light is OFF
if(LightStatus==HIGH) // light gets turned ON
LiteON = millis()   // log the system time
ONflag = HIGH
}

if (ONflag == HIGH {    // only HIGH when the light is ON
if (lightStatus == LOW )  //  light gets turned off
LightOFF = millis() // log the system time
ONflag = LOW
}

TimeOn = LightOFF - LightON;
duration = duration + TimeOn;

write to SD card

I would suggest you use a RTC and log the time and date it goes  ON
log the time and date it goes OFF  and the TimeOn for THIS time, and duration as running count

you need to set your variables as  unsigned long for any times

Go Up