مؤقت#
مقدمة#
يتم استخدام فئة المؤقت timer للحفاظ على الوقت والتفاعل مع مؤقت مستقل عن مؤقت الدماغ.
مُنشئ الفئة#
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#
يضبط المؤقت على الصفر.
Available Functionsvoid reset();
لا تقبل هذه الدالة أي معلمات.
Return Valuesهذه الدالة لا تُرجع قيمة.
Exampleswhile (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 Functionsdouble value();
لا تقبل هذه الدالة أي معلمات.
Return Valuesعدد مزدوج يمثل مقدار الوقت المنقضي بالثواني.
Notesيبدأ المؤقت بالعد عند إنشائه.
Calling
resetresets the timer value to zero.
// 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 Functions1 — يسجل دالة رد نداء ليتم تشغيلها بعد تأخير محدد ويمرر قيمة محددة من قبل المستخدم إلى دالة رد النداء.
static void event( void (*callback)(void *), uint32_t value );
Parameters2 — يسجل دالة رد نداء ليتم تشغيلها بعد تأخير محدد.
static void event( void (*callback)(void), uint32_t value );
المعلمة |
يكتب |
وصف |
|---|---|---|
|
|
دالة سيتم استدعاؤها بعد التأخير المحدد وتستقبل وسيطًا محددًا من قبل المستخدم. |
|
|
دالة سيتم استدعاؤها بعد التأخير المحدد. |
|
|
التأخير، بالمللي ثانية، قبل تنفيذ دالة الاستدعاء. |
هذه الدالة لا تُرجع قيمة.
Notesتقوم هذه الوظيفة بجدولة عملية رد نداء لمرة واحدة؛ فهي لا تتكرر تلقائيًا.
يجب أن تُرجع دالة الاستدعاء القيمة
void.قد يتم جدولة عدة فعاليات في نفس الوقت.
عرّف الدالة (خارج النطاق
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); }