Μετρών την ώραν#

Εισαγωγή#

Ο Χρονοδιακόπτης στο VEX IQ (2ης γενιάς) σάς επιτρέπει να παρακολουθείτε τον χρόνο που έχει παρέλθει και να εκτελείτε ενέργειες με βάση χρονικά διαστήματα. Μπορεί να χρησιμοποιηθεί για να μετρήσετε πόσο χρόνο χρειάζεται κάτι ή να το επαναφέρετε για νέες λειτουργίες χρονισμού.

Παρακάτω είναι μια λίστα με όλες τις μεθόδους:

Μέθοδοι — Έλεγχος και αλληλεπίδραση με το χρονόμετρο του εγκεφάλου.

  • time — Returns how much time has passed.

  • clear — Resets the timer to zero.

  • system — Returns the number of milliseconds the Brain has been powered on.

  • system_high_res — Returns the number of microseconds the Brain has been powered on.

  • event — Registers a function to be called after a specified number of milliseconds.

Κατασκευαστής — Δημιουργήστε επιπλέον χρονόμετρα.

  • Timer — Creates an additional timer.

φορά#

time returns the time since the timer was last reset as a decimal. The timer is automatically reset at the start of a project.

Usage:
brain.timer.time(units)

Παράμετροι

Περιγραφή

units

The unit that represents the time: MSEC (default) – milliseconds, or SECONDS

# Display the current time on the timer
while True:
    brain.screen.set_cursor(1, 1)
    brain.screen.clear_screen()
    brain.screen.print(brain.timer.time(SECONDS))
    wait(50, MSEC)

σαφής#

clear sets the timer to zero. This can be used to time additional sections of code within the same project.

Usage:
brain.timer.clear()

Παράμετροι

Περιγραφή

Αυτή η μέθοδος δεν έχει παραμέτρους.

# Reset the timer when a button is pressed
while True:
    brain.screen.set_cursor(1, 1)
    brain.screen.clear_screen()
    brain.screen.print(brain.timer.time(SECONDS))
    wait(50, MSEC)
    if brain.buttonCheck.pressing():
        brain.timer.clear()

σύστημα#

system returns the number of milliseconds the brain has been powered on.

Usage:
brain.timer.system()

Παράμετροι

Περιγραφή

Αυτή η μέθοδος δεν έχει παραμέτρους.

# Display the time the brain has been on in milliseconds
while True:
    brain.screen.set_cursor(1, 1)
    brain.screen.clear_screen()
    brain.screen.print(brain.timer.system())
    brain.screen.print(" MSEC")
    wait(50, MSEC)

σύστημα_υψηλής_ανάλυσης#

system_high_res returns the number of microseconds the brain has been powered on.

Usage:
brain.timer.system_high_res()

Παράμετροι

Περιγραφή

Αυτή η μέθοδος δεν έχει παραμέτρους.

# Display the time the brain has been on in microseconds
while True:
    brain.screen.set_cursor(1, 1)
    brain.screen.clear_screen()
    brain.screen.print(brain.timer.system_high_res())
    wait(50, MSEC)

συμβάν#

event calls a function after a specified amount of time passes.

Usage:
brain.timer.event(callback, delay, arg)

Παράμετροι

Περιγραφή

callback

Μια συνάρτηση που θα εκτελεστεί όταν συμβεί το συμβάν χρονοδιακόπτη.

delay

Η καθυστέρηση πριν από την κλήση της συνάρτησης, σε χιλιοστά του δευτερολέπτου.

arg

Προαιρετικό. Μια πλειάδα που περιέχει ορίσματα για να μεταβιβαστούν στη συνάρτηση επανάκλησης. Δείτε Συναρτήσεις με Παραμέτρους για περισσότερες πληροφορίες.

# Define a function timer_event
def timer_event():
    drivetrain.drive_for(FORWARD, 200, MM)

# Drive forward after a 5000 millisecond delay
brain.timer.event(timer_event, 5000)

Κατασκευαστές#

Constructors are used to manually create Timer objects, which are necessary for creating any additional timers besides brain.timer.

For the examples below, the configured Timer will be named timer_1 and will be used in all subsequent examples throughout this API documentation when referring to Timer class methods.

Timer#

Timer creates a new timer. A Timer object will immediately begin counting the moment it is created and will work with all brain.timer methods.

Usage:
Timer()

Παράμετροι

Περιγραφή

Αυτός ο κατασκευαστής δεν έχει παραμέτρους.

wait(2, SECONDS)
timer_1 = Timer()
while True:
    brain.screen.clear_screen()
    brain.screen.set_cursor(1, 1)
    brain.screen.print("Brain: ")
    brain.screen.print(brain.timer.time(SECONDS))
    brain.screen.next_row()
    brain.screen.print("timer_1: ")
    brain.screen.print(timer_1.time(SECONDS))
    wait(15, MSEC)