Place to put your Basic demos and examples

Moderator: Mmiscool

User avatar
By ukioye
#67740 I was recently playing with the function millis().
It is documented as 'Will return number of milliseconds since boot time.' but it seems to return the time since the application was started...whatever..
I wrote the following to parse it into a (more) human readable form.
The coding is deliberately long winded for ease of understanding; like : if SecsUp > (24 * 60 * 60) is written to show 24 hours * 60 minutes * 60 seconds...for speed you would be better to use SecsUp>86400 to save recalculating each time round.
Note also the use of the modulo operator '%' to get the balance of Secs remaining.
Enjoy!
Code: Select allmemclear
cls
time.setup(+10,0) '10 hours in front of Greenwich, no daylight saving
timer 10000, [readData] ' ## Time for auto refresh variables ##
wprint |<html><body>|
wprint |<p><font face="Helvetica" size="6">Timeup: |
textbox TimeUp
wprint |</font></p>|

wprint "<p> Click to Exit <br>"
button "Exit", [cleanExit]
wprint |</body></html>|
Wait

[cleanExit]  'do stop the timer or it is difficult to get to debug
timer 0
end

[readData]
'millis() to days:hrs:min:sec
upTime = millis() ' for debug
SecsUp = int(millis() / 1000)
MinsUp = 0
HrsUp = 0
DaysUp = 0

if SecsUp >= (24*60*60) then
   DaysUp = int(SecsUp / (24*60*60))
   SecsUp = SecsUp % (DaysUp*24*60*60) 'decrement Day(s) worth of Seconds
end if   
if SecsUp >= (24*60) then
   HrsUp = int(SecsUp / (24*60))
   SecsUp = SecsUp % (HrsUp*24*60) 'decrement Hr(s) worth of Seconds
end if   
if SecsUp >= (60) then
   MinsUp = int(SecsUp/60)
   SecsUp = SecsUp % (MinsUp*60) 'decrement Min(s) worth of Seconds
end if   
TimeUp = DaysUp & "d:" & HrsUp & "h:" & MinsUp & "m:" & SecsUp & "s"
'--------------------------------------------