File tree Expand file tree Collapse file tree 3 files changed +12
-18
lines changed
Expand file tree Collapse file tree 3 files changed +12
-18
lines changed Original file line number Diff line number Diff line change 5151import time
5252import sys
5353
54- # Define a function to get milliseconds. This depends on the platform
55- if hasattr (time , "ticks_ms" ):
56- # MicroPython: time.time() gives an integer, have to instead use ticks_ms()
54+ # Provide platform-dependent way to get current time in milliseconds
55+ if hasattr (time , "monotonic_ns" ):
5756 def millis ():
58- return time .ticks_ms ()
57+ return time .monotonic_ns () // 1000000 # works in CircuitPython and Linux/Raspberry Pi
5958else :
60- # Other platforms: time.time() gives a float
6159 def millis ():
62- return int ( round ( time .time () * 1000 ))
60+ return time .time_ns () // 1000000 #only works in MicroPython
6361
6462def runExample ():
6563
Original file line number Diff line number Diff line change 5656import time
5757import sys
5858
59- # Define a function to get milliseconds. This depends on the platform
60- if hasattr (time , "ticks_ms" ):
61- # MicroPython: time.time() gives an integer, have to instead use ticks_ms()
59+ # Provide platform-dependent way to get current time in milliseconds
60+ if hasattr (time , "monotonic_ns" ):
6261 def millis ():
63- return time .ticks_ms ()
62+ return time .monotonic_ns () // 1000000 # works in CircuitPython and Linux/Raspberry Pi
6463else :
65- # Other platforms: time.time() gives a float
6664 def millis ():
67- return int ( round ( time .time () * 1000 ))
65+ return time .time_ns () // 1000000 #only works in MicroPython
6866
6967def runExample ():
7068
Original file line number Diff line number Diff line change 5252import time
5353import sys
5454
55- # Define a function to get milliseconds. This depends on the platform
56- if hasattr (time , "ticks_ms" ):
57- # MicroPython: time.time() gives an integer, have to instead use ticks_ms()
55+ # Provide platform-dependent way to get current time in milliseconds
56+ if hasattr (time , "monotonic_ns" ):
5857 def millis ():
59- return time .ticks_ms ()
58+ return time .monotonic_ns () // 1000000 # works in CircuitPython and Linux/Raspberry Pi
6059else :
61- # Other platforms: time.time() gives a float
6260 def millis ():
63- return int ( round ( time .time () * 1000 ))
61+ return time .time_ns () // 1000000 #only works in MicroPython
6462
6563def runExample ():
6664
You can’t perform that action at this time.
0 commit comments