مؤقت#
مقدمة#
يتتبع مؤقت وحدة التحكم في طائرة VEX AIR بدون طيار الوقت المنقضي منذ بداية المشروع. ويمكن استخدامه لقياس المدة التي يستغرقها شيء ما أو إعادة ضبطه لعمليات التوقيت الجديدة.
فيما يلي قائمة بجميع الطرق المتاحة:
الإجراء – التحكم في المؤقت.
reset– يعيد ضبط المؤقت إلى الصفر.
الدالة المُسترجعة – تُبلغ عن قيمة المؤقت الحالية.
time– تُرجع مقدار الوقت الذي انقضى.
استدعاء - تشغيل الوظائف بعد تأخير.
event– يسجل دالة ليتم استدعاؤها بعد عدد محدد من المللي ثانية.
المنشئ - إنشاء مؤقت لتتبع الوقت.
Timer- إنشاء كائن مؤقت جديد يمكن استخدامه مع هذه الطرق.
فعل#
reset#
إعادة الضبط reset تُعيد المؤقت إلى الصفر. يمكن استخدام هذا لتوقيت أجزاء إضافية من التعليمات البرمجية ضمن نفس المشروع.
Usage:
timer.reset()
حدود |
وصف |
|---|---|
لا تحتوي هذه الطريقة على أي معلمات. |
# Display the time the drone takes to climb upwards.
drone.take_off(500)
timer.reset()
drone.climb_for(UP, 500)
controller.screen.print("Time elapsed: ")
controller.screen.print(timer.time(SECONDS))
drone.land()
المحصل#
time#
يُعيد الأمر time الوقت المنقضي منذ آخر إعادة ضبط للمؤقت كعدد عشري. تتم إعادة ضبط المؤقت تلقائيًا عند بدء المشروع.
Usage:
timer.time(units)
حدود |
وصف |
|---|---|
|
الوحدة التي تمثل الوقت: |
# Display the time in two units.
while True:
controller.screen.clear_screen()
controller.screen.set_cursor(1, 1)
controller.screen.print("Time: {} ms".format(timer.time(MSEC)))
controller.screen.next_row()
controller.screen.print("Time: {:.2f} s".format(timer.time(SECONDS)))
wait(50, MSEC)
أتصل مرة أخرى#
event#
الحدث event فترة زمنية محددة.
طريقة الاستخدام:
timer.event(callback, delay, arg)
حدود |
وصف |
|---|---|
|
دالة يتم تنفيذها عند حدوث حدث المؤقت. |
|
التأخير قبل استدعاء الدالة، بالمللي ثانية. |
|
اختياري. مجموعة تحتوي على الوسائط التي يتم تمريرها إلى دالة الاستدعاء. راجع استخدام الأحداث مع المعلمات لمزيد من المعلومات. |
# Create a function to play a looping sound.
def on_timer():
controller.sound.play(LOOPING)
# Play the sound after 4 seconds (4000 mS).
timer.event(on_timer, 4000)
المُنشئ#
Timer#
Timer creates a new timer. A Timer object will immediately begin counting the moment it is created and will work with all timer methods.
Usage:
Timer()
المعلمة |
وصف |
|---|---|
لا يحتوي هذا المُنشئ على أي معلمات. |
# Display 2 timers with a 2 second difference.
wait(2, SECONDS)
stopwatch = Timer()
while True:
controller.screen.clear_screen()
controller.screen.set_cursor(1, 1)
controller.screen.print("Timer: ")
controller.screen.print(timer.time(SECONDS))
controller.screen.set_cursor(4, 1)
controller.screen.print("Stopwatch: ")
controller.screen.print(stopwatch.time(SECONDS))
wait(0.1, SECONDS)