itsybitsy circuitpython measuring time time.clock()

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
frednikgohar
 
Posts: 14
Joined: Wed Aug 11, 2021 2:33 pm

itsybitsy circuitpython measuring time time.clock()

Post by frednikgohar »

I'm trying to measure time between two events in my Circuit Python app running on an ItsyBitsy Express (prod page: https://www.adafruit.com/product/4481)

I've used the time module in a desktop app before and I know that Circuit Python does have a time module - for example:

Code: Select all

import time
time.sleep(1)
will pause execution for 1 sec.

However, time.clock() doesn't seem to be supported. The following code

Code: Select all

import time

t = time.clock
x = time.
print(t)
Throws the following error

Code: Select all

21:47:46.421 -> soft reboot
21:47:46.421 -> 
21:47:46.421 -> Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
21:47:46.489 -> code.py output:
21:47:46.489 -> Traceback (most recent call last):
21:47:46.489 ->   File "code.py", line 5
21:47:46.489 -> SyntaxError: invalid syntax
21:47:46.489 -> 
21:47:46.489 -> Code done running.
21:47:46.489 -> 
21:47:46.489 -> Press any key to enter the REPL. Use CTRL-D to reload.
Is time.clock() not supported in CP and/or my particular board?

Either way, I want to measure the time difference from the time an LED lights up till the user pushes a button. How can I go about this? Thanks in advance for helping out a newbie prorammer.

User avatar
frednikgohar
 
Posts: 14
Joined: Wed Aug 11, 2021 2:33 pm

Re: itsybitsy circuitpython measuring time time.clock()

Post by frednikgohar »

It appears that one possible solution is to use time.monotonic() which outputs the number of seconds since the board was last powered up. If so, one should be able to call it in both Event1 and Event2, subtract, and get the difference.

I have tested it and it works on ItsyBitsy Express. What is not yet clear is the function's resolution... for example, can it do milliseconds?

User avatar
Franklin97355
 
Posts: 23938
Joined: Mon Apr 21, 2008 2:33 pm

Re: itsybitsy circuitpython measuring time time.clock()

Post by Franklin97355 »


Locked
Please be positive and constructive with your questions and comments.

Return to “Itsy Bitsy Boards”