Go Down

Topic: Help with millis() (Read 190 times) previous topic - next topic

Talor

I am a little confused with my program involving "millis()",

I am trying to keep track of intervals with seconds, not milliseconds.
What would be the process of converting "millis()" to keep track of seconds?

I have been having trouble with trying to modify it but I'm stuck.



ieee488

a millisecond = 1000 seconds


Talor

Yes, I know the conversion. I simply want to make it so instead of milliseconds being shown in the serial monitor seconds are displayed instead. I am having trouble trying to define "millis()=millis()/1000"


ieee488

#3
Jul 17, 2017, 03:49 pm Last Edit: Jul 17, 2017, 03:49 pm by ieee488
millis()=millis()/1000


Look at that again.
What do you think that code is doing?
If you don't know, print out the result.



jremington

Try
Code: [Select]
Serial.println( (millis()+500)/1000); //rounding

MarkT

a millisecond = 1000 seconds


That would be a kilosecond, ks, not a millisecond! (seldom used, as we call 3.6ks an 'hour')
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

MarkT

Code: [Select]

long seconds ()
{
  return millis() / 1000 ;
}
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

MorganS

Try
Code: [Select]
Serial.println( (millis()+500)/1000); //rounding
Do you round birthdays? When you're 6 months old you're also a year old?

Time is one of the few things where you usually want truncation instead of rounding.
"The problem is in the code you didn't post."

jremington

#8
Jul 18, 2017, 12:55 am Last Edit: Jul 18, 2017, 02:25 am by jremington
Quote
where you usually want truncation
Not I. I want to know approximately how many seconds have passed, to the closest value.

I tend to consider, for example, 1.999 seconds as 2 seconds, but to each his/her own. People certainly do lie about their ages, often truncating much, much more than 6 months.

ieee488

That would be a kilosecond, ks, not a millisecond! (seldom used, as we call 3.6ks an 'hour')
A brain fart.

Should read 1 seconds = 1000 milliseconds

Go Up