مؤقت#
مقدمة#
يتتبع مؤقت روبوت البرمجة VEX AIM الوقت المنقضي منذ بداية المشروع. ويمكن استخدامه لقياس المدة التي يستغرقها إنجاز مهمة ما أو إعادة ضبطه لعمليات التوقيت الجديدة.
فيما يلي قائمة بجميع الطرق:
الأساليب – التحكم في المؤقت.
reset– يعيد ضبط المؤقت إلى الصفر.time– تُرجع مقدار الوقت الذي انقضى.event– يسجل دالة ليتم استدعاؤها بعد عدد محدد من المللي ثانية.
المنشئ – إنشاء مؤقت لتتبع الوقت.
Timer– إنشاء كائن مؤقت جديد يمكن استخدامه مع هذه الطرق.
طُرق#
reset#
إعادة الضبط reset تُعيد المؤقت إلى الصفر. يمكن استخدام هذا لتوقيت أجزاء إضافية من التعليمات البرمجية ضمن نفس المشروع.
طريقة الاستخدام:
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 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:
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)