시간제 노동자#

소개#

VEXcode VR의 타이머를 사용하면 경과 시간을 추적하고 시간 간격에 따라 작업을 수행할 수 있습니다. 특정 작업에 걸리는 시간을 측정하거나 새로운 타이밍 작업을 위해 시간을 재설정하는 데 사용할 수 있습니다.

다음은 모든 방법 목록입니다.

방법 – 브레인의 타이머를 제어하고 상호 작용합니다.

  • timer_reset – 타이머를 0으로 재설정합니다.

  • timer_time – 경과된 시간을 반환합니다.

  • timer_event – 지정된 밀리초 후에 호출될 함수를 등록합니다.

timer_reset#

timer_reset 타이머를 0으로 설정합니다. 이는 동일한 프로젝트 내의 다른 코드 섹션의 실행 시간을 측정하는 데 사용할 수 있습니다.

Usage:
brain.timer_reset()

매개변수

설명

이 메서드에는 매개변수가 없습니다.

def main():
    # Reset the timer every 3 seconds
    while True:
        brain.clear()
        brain.print(brain.timer.time(SECONDS))
        if brain.timer_time(SECONDS) > 3: 
            brain.timer_reset()
        wait(5, MSEC)

# VR threads — Do not delete
vr_thread(main)

timer_time#

timer_time 타이머가 마지막으로 재설정된 이후 경과된 시간을 소수점으로 반환합니다. 타이머는 프로젝트 시작 시 자동으로 재설정됩니다.

Usage:
brain.timer_time(units)

매개변수

설명

units

시간을 나타내는 단위: SECONDS

def main():
    # Display the current time on the timer
    while True:
        brain.clear()
        brain.print(brain.timer_time(SECONDS))
        wait(50, MSEC)

# VR threads — Do not delete
vr_thread(main)

timer_event#

timer_event 지정된 시간이 경과한 후 함수를 호출합니다.

Usage:
brain.timer_event(callback, delay)

매개변수

설명

callback

타이머 이벤트가 발생했을 때 실행될 함수입니다.

delay

함수가 호출되기 전의 지연 시간(밀리초).

def timer_event():
    # Drive forward
    drivetrain.drive_for(FORWARD, 200, MM)

def main():
    # Drive forward after a 5000 millisecond delay
    brain.timer_event(timer_event, 5000)

# VR threads — Do not delete
vr_thread(main)