From 98dc4b5029d7b4141793627a5ebbb58a8f3f0329 Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Fri, 11 Nov 2022 21:39:14 +0700 Subject: [PATCH] add collision delay --- kuukar/kuukar_collision.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/kuukar/kuukar_collision.py b/kuukar/kuukar_collision.py index 3a423eb..ad0016e 100644 --- a/kuukar/kuukar_collision.py +++ b/kuukar/kuukar_collision.py @@ -1,9 +1,11 @@ from telemetrix_rpi_pico import telemetrix_rpi_pico from kuukar.kuukar_config import COLLISION_DETECTOR_PIN, COLLISION_ENABLE - from kuukar.kuukar_lcd import lcd from kuukar.kuukar_leds import leds +from time import perf_counter as pc + class collision: + lastCollision_ts = 0 def __init__(self, mcu: telemetrix_rpi_pico.TelemetrixRpiPico, lcd: lcd, leds: leds) -> None: self.mcu = mcu self.lcd = lcd @@ -13,5 +15,6 @@ class collision: def collision_handle(self, data): val = data[2] - if val == 1: - self.lcd.play_video("keke_hurt") \ No newline at end of file + if val == 1 and pc() - self.lastCollision_ts > 1.5: + self.lcd.play_video("keke_hurt") + self.lastCollision_ts = pc() \ No newline at end of file