ตัวจับเวลา#

การแนะนำ#

ตัวจับเวลาใน VEX GO ช่วยให้คุณติดตามเวลาที่ผ่านไปและดำเนินการต่างๆ ตามช่วงเวลาที่กำหนด สามารถใช้เพื่อวัดระยะเวลาที่ใช้ในการทำสิ่งใดสิ่งหนึ่ง หรือตั้งค่าใหม่เพื่อเริ่มการจับเวลาครั้งใหม่ได้

ด้านล่างนี้คือรายการวิธีการทั้งหมด:

วิธีการ – ควบคุมและโต้ตอบกับตัวจับเวลาของสมอง

  • reset – รีเซ็ตตัวจับเวลาเป็นศูนย์

  • time – ส่งคืนว่าเวลาผ่านไปนานเท่าใด

  • event – ลงทะเบียนฟังก์ชันที่จะถูกเรียกหลังจากจำนวนมิลลิวินาทีที่กำหนด

ตัวสร้าง – สร้างตัวจับเวลาเพิ่มเติม

  • Timer – สร้างตัวจับเวลาเพิ่มเติม

รีเซ็ต#

reset จะตั้งค่าตัวจับเวลาเป็นศูนย์ สามารถใช้เพื่อจับเวลาส่วนอื่นๆ ของโค้ดภายในโปรเจกต์เดียวกันได้

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 จะแสดงเวลาตั้งแต่รีเซ็ตตัวจับเวลาครั้งล่าสุดในรูปแบบทศนิยม ตัวจับเวลาจะถูกรีเซ็ตโดยอัตโนมัติเมื่อเริ่มต้นโครงการ

Usage:
timer.time(units)

พารามิเตอร์

คำอธิบาย

units

หน่วยที่ใช้แสดงเวลา: MSEC (ค่าเริ่มต้น) – มิลลิวินาที หรือ SECONDS

# 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)

พารามิเตอร์

คำอธิบาย

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)