Go Down

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

#### Talor

##### Jul 17, 2017, 03:35 pm
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

#1
##### Jul 17, 2017, 03:35 pm
a millisecond = 1000 seconds

#### Talor

#2
##### Jul 17, 2017, 03:43 pm
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 pmLast 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

#4
##### Jul 17, 2017, 04:44 pm
Try
Code: [Select]
`Serial.println( (millis()+500)/1000); //rounding`

#### MarkT

#5
##### Jul 17, 2017, 11:18 pm
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

#6
##### Jul 17, 2017, 11:19 pm
Code: [Select]
`long seconds (){  return millis() / 1000 ;}`
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

#### MorganS

#7
##### Jul 18, 2017, 12:18 am
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 amLast 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

#9
##### Jul 18, 2017, 01:49 am
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