Nick_Gkoutzas
Nick_Gkoutzas

Reputation: 49

Is there a function like millis() of Arduino in python?

Is there a function like millis() of Arduino (not delay() function) in python? I want to stop a specific part of program for a while ,but not the whole program.

Upvotes: 0

Views: 1357

Answers (3)

ACimander
ACimander

Reputation: 1979

This question is a little unclear, since millis() just gives you the time since the program started execution, but you want to pause parts of your program.

A Python script runs as a single-threaded process, if you want to block a specific part of your program while not blocking the rest, you first need to start up additional threads and/or processes and split your logic across them.

AFAIK there's no builtin "time since startup" variable (but I might be wrong, of course, happy to learn otherwise), I would add a time.time() call to your __main__ block:

import time


def main():
    global time_of_startup

    # ... lots of code here ... 

    time_since_start = time.time() - time_of_startup


if __name__ == "__main__":
    time_of_startup = time.time()
    main()

Upvotes: 0

Sherin Jayanand
Sherin Jayanand

Reputation: 204

Try using utime functions

https://docs.micropython.org/en/latest/library/utime.html

Hope that helps.

Upvotes: 1

Sherin Jayanand
Sherin Jayanand

Reputation: 204

Did you try using

import time
seconds_to_sleep=1
time.sleep(seconds_to_sleep)

Upvotes: 0

Related Questions