시간제 노동자#

소개#

timer 클래스는 Brain의 타이머와 독립적으로 시간을 유지하고 타이머와 상호 작용하는 데 사용됩니다.

클래스 생성자#

timer();

클래스 소멸자#

timer 객체를 파괴하고 관련 리소스를 해제합니다.

~timer();

매개변수#

이 생성자는 매개변수를 받지 않습니다.

예시#

// Create a timer instance
timer myTimer = timer();

회원 기능#

timer 클래스는 다음과 같은 멤버 함수를 포함합니다.

  • reset — Resets the timer to zero.

  • value — Returns the elapsed time since the timer started.

  • event — 지정된 밀리초 후에 함수를 호출하며 선택적 인수를 사용합니다.

timer 멤버 함수를 호출하기 전에 아래와 같이 timer 인스턴스를 생성해야 합니다.

/* This constructor is required to use a 
custom timer. Replace the values
as needed. */

// Create a timer instance
timer myTimer = timer();

/* This constructor is required when using VS Code.
A Brain is generated automatically at the start of
VEXcode projects. */

// Create the Brain to use Brain.Timer
brain Brain = brain();

reset#

타이머를 0으로 설정합니다.

Available Functions
void reset();

Parameters

이 함수는 매개변수를 받지 않습니다.

Return Values

이 함수는 값을 반환하지 않습니다.

Examples
while (true) {
  // Clear the timer every time the screen is pressed
  if (Brain.Screen.pressing()) {
    myTimer.reset();
  }
  Brain.Screen.clearScreen();
  Brain.Screen.setCursor(1, 1);
  Brain.Screen.print("Time: %.2f", myTimer.value());
  wait(50, msec);
}

value#

타이머의 현재 값을 반환합니다.

Available Functions
double value();

Parameters

이 함수는 매개변수를 받지 않습니다.

Return Values

경과된 시간을 초 단위로 나타내는 더블 타입 값입니다.

Notes
  • 타이머는 제작되는 순간부터 카운트를 시작합니다.

  • Calling reset resets the timer value to zero.

Examples
// Display the timer as it ticks up
while (true) {
  Brain.Screen.clearScreen();
  Brain.Screen.setCursor(1, 1);
  Brain.Screen.print("Time: %.2f", myTimer.value());

  wait(50, msec);
}

event#

지정된 지연 시간 후에 실행될 콜백 함수를 등록합니다.

Available Functions

1 — 지정된 지연 시간 후에 실행될 콜백을 등록하고 사용자 정의 값을 콜백에 전달합니다.

static void event(
    void (*callback)(void *),
    uint32_t value );

2 — 지정된 지연 시간 후에 실행될 콜백을 등록합니다.

static void event(
    void (*callback)(void),
    uint32_t value );

Parameters

매개변수

유형

설명

callback

void (*)(void *)

지정된 지연 시간 후에 호출되며 사용자가 정의한 인수를 받는 함수입니다.

callback

void (*)(void)

지정된 지연 시간 후에 호출될 함수입니다.

value

uint32_t

콜백 함수가 실행되기까지의 지연 시간(밀리초)입니다.

Return Values

이 함수는 값을 반환하지 않습니다.

Notes
  • 이 함수는 일회성 콜백을 예약하며, 자동으로 반복 실행되지 않습니다.

  • 콜백 함수는 void 반환해야 합니다.

  • 여러 행사가 동시에 예약될 수 있습니다.

Examples

함수를 정의하십시오 ( int main() 외부).

// Create a function to turn the screen orange
void turnOrange() {
  Brain.Screen.clearScreen(orange);
}

int main() 내부에 함수를 등록합니다.

int main() {
  /* vexcodeInit() is only required when using VEXcode.
  Remove vexcodeInit() if compiling in VS Code. */
  vexcodeInit();

  timer myTimer = timer();
  // Call turnOrange after 2 seconds
  myTimer.event(turnOrange, 2000);
}