Μετρών την ώραν#
Εισαγωγή#
Ο Χρονοδιακόπτης στο VEX GO σάς επιτρέπει να παρακολουθείτε τον χρόνο που έχει παρέλθει και να εκτελείτε ενέργειες με βάση χρονικά διαστήματα. Μπορεί να χρησιμοποιηθεί για να μετρήσετε πόσο χρόνο χρειάζεται κάτι ή να το επαναφέρετε για νέες λειτουργίες χρονισμού.
Παρακάτω είναι μια λίστα με όλες τις μεθόδους:
Μέθοδοι – Έλεγχος και αλληλεπίδραση με το χρονόμετρο του εγκεφάλου.
reset– Resets the timer to zero.time– Returns how much time has passed.event– Registers a function to be called after a specified number of milliseconds.
Κατασκευαστής – Δημιουργήστε επιπλέον χρονόμετρα.
Timer– Creates an additional timer.
επαναφορά#
reset sets the timer to zero. This can be used to time additional sections of code within the same project.
Usage:
timer.reset()
Παράμετροι |
Περιγραφή |
|---|---|
Αυτή η μέθοδος δεν έχει παραμέτρους. |
# Build Used: Super Code Base 2.0
def main():
# Reset the timer when the bumper is pressed
while True:
console.clear()
console.print(timer.time(SECONDS))
wait(50, MSEC)
if bumper.is_pressed():
timer.reset()
# Start threads — Do not delete
start_thread(main)
φορά#
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:
timer.time(units)
Παράμετροι |
Περιγραφή |
|---|---|
|
The unit that represents the time: |
# Build Used: Super Code Base 2.0
def main():
# Display the time until the bumper is pressed
while True:
console.clear()
console.print(timer.time(SECONDS))
wait(50, MSEC)
if bumper.is_pressed():
timer.reset()
# Start threads — Do not delete
start_thread(main)
συμβάν#
event calls a function after a specified amount of time passes.
Usage:
timer.event(callback, delay, arg)
Παράμετροι |
Περιγραφή |
|---|---|
|
Μια συνάρτηση που θα εκτελεστεί όταν συμβεί το συμβάν χρονοδιακόπτη. |
|
Η καθυστέρηση πριν από την κλήση της συνάρτησης, σε χιλιοστά του δευτερολέπτου. |
|
Προαιρετικό. Μια πλειάδα που περιέχει ορίσματα για να περάσουν στη συνάρτηση επανάκλησης. Δείτε Συναρτήσεις με Παραμέτρους για περισσότερες πληροφορίες. |
# Build Used: Super Code Base 2.0
def timer_event():
drivetrain.drive_for(FORWARD, 200, MM)
def main():
# Drive forward after a 5000 millisecond delay
timer.event(timer_event, 5000)
# Start threads — Do not delete
start_thread(main)
Κατασκευαστές#
Timer#
Timer creates a new timer. A Timer object will immediately begin counting the moment it is created and will work with all timer methods.
Usage:
my_timer = Timer()
Παράμετροι |
Περιγραφή |
|---|---|
Αυτός ο κατασκευαστής δεν έχει παραμέτρους. |
def main():
# Display the time of two timers
wait(2, SECONDS)
timer_1 = Timer()
while True:
console.clear()
console.print("Timer: ", timer.time(SECONDS))
console.new_line()
console.print("timer_1: ", timer_1.time(SECONDS))
wait(15, MSEC)
# Start threads — Do not delete
start_thread(main)