사용자 지정 타이머#

소개#

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

클래스 생성자#

timer();

클래스 소멸자#

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

~timer();

매개변수#

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

예시#

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

회원 기능#

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

  • clear — 타이머를 0으로 재설정합니다.

  • time — 타이머가 시작된 이후 경과된 시간을 반환합니다.

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

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

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

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

clear#

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

Available Functions
void clear();

Parameters

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

Return Values

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

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

time#

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

Available Functions

1 — 경과 시간을 밀리초 단위로 반환합니다.

uint32_t time() const;

2 — 지정된 시간 단위로 경과 시간을 반환합니다.

double time(
    timeUnits units ) const;

Parameters

매개변수

유형

설명

units

timeUnits

경과 시간을 반환하는 데 사용되는 단위:

  • seconds sec —초
  • msec —밀리초

Return Values
  • 매개변수가 없는 함수(1)는 경과 시간을 밀리초 단위로 나타내는 uint32_t 을 반환합니다.

  • timeUnits 매개변수(2)를 갖는 함수는 지정된 단위로 경과 시간을 나타내는 double 을 반환합니다.

Notes
  • 사용자 지정 타이머가 생성되는 시점부터 타이머 카운트가 시작됩니다.

  • clear를 호출하면 타이머 값이 0으로 재설정됩니다.

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

  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);
}