시간제 노동자#
소개#
VEX AIM 코딩 로봇의 타이머는 프로젝트 시작부터 경과 시간을 기록합니다. 특정 작업에 걸리는 시간을 측정하거나 새로운 타이밍 작업을 위해 타이머를 재설정하는 데 사용할 수 있습니다.
다음은 모든 방법 목록입니다.
방법 – 타이머를 제어합니다.
생성자 – 시간을 추적하는 타이머를 생성합니다.
Timer– 이러한 메서드와 함께 사용할 수 있는 새 타이머 객체를 생성합니다.
행동 양식#
reset#
reset 타이머를 0으로 설정합니다. 이 기능은 동일한 프로젝트 내의 다른 코드 섹션의 실행 시간을 측정하는 데 사용할 수 있습니다.
용법:
timer.reset()
매개변수 |
설명 |
|---|---|
이 메서드에는 매개변수가 없습니다. |
# Display how long a turn takes
robot.move_for(100, 0)
timer.reset()
robot.turn_for(RIGHT, 90)
robot.screen.print("Time elapsed:")
robot.screen.next_row()
robot.screen.print("%d seconds" % timer.time(SECONDS))
time#
time 타이머가 마지막으로 재설정된 이후 경과된 시간을 소수점으로 반환합니다. 타이머는 프로젝트 시작 시 자동으로 재설정됩니다.
용법:
timer.time(units)
매개변수 |
설명 |
|---|---|
|
시간을 나타내는 단위: |
# Print the time in seconds
# and in milliseconds on the next row.
while timer.time(SECONDS) <= 5:
robot.screen.clear_screen()
robot.screen.set_cursor(1, 1)
robot.screen.print("Time: %d" % timer.time(MSEC))
robot.screen.next_row()
robot.screen.print("Time: %.2f" % timer.time(SECONDS))
wait(50, MSEC)
event#
event 지정된 시간이 지난 후 함수를 호출합니다.
용법:
timer.event(callback, delay, arg)
매개변수 |
설명 |
|---|---|
|
타이머 이벤트가 발생했을 때 실행될 함수입니다. |
|
함수가 호출되기 전의 지연 시간(밀리초). |
|
선택 사항입니다. 콜백 함수에 전달할 인수를 포함하는 튜플입니다. 자세한 내용은 매개변수가 있는 이벤트 사용을 참조하세요. |
# Create a function to play a sparkle sound
def timer_callback():
robot.sound.play(SPARKLE)
# Call the function after 2000 milliseconds (2 seconds)
timer.event(timer_callback, 2000)
건설자#
Timer#
Timer 새 타이머를 생성합니다. Timer 객체는 생성되는 순간부터 즉시 카운트를 시작하며 timer 의 모든 메서드와 함께 작동합니다.
Usage:
Timer()
매개변수 |
설명 |
|---|---|
이 생성자에는 매개변수가 없습니다. |
## Display 2 timers with a 2 second difference
wait(2, SECONDS)
stopwatch = Timer()
while True:
robot.screen.clear_screen()
robot.screen.set_cursor(1, 1)
robot.screen.print("Timer:")
robot.screen.set_cursor(2, 1)
robot.screen.print(timer.time(SECONDS))
robot.screen.set_cursor(4, 1)
robot.screen.print("Stopwatch:")
robot.screen.set_cursor(5, 1)
robot.screen.print(stopwatch.time(SECONDS))
wait(0.1, SECONDS)