From bcc6e4147d238b20c5cabd0e07129986a6dbf1c1 Mon Sep 17 00:00:00 2001 From: vitrinekast Date: Wed, 26 Jun 2024 17:52:36 +0200 Subject: [PATCH] listen to sensor change for audio --- script.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/script.py b/script.py index 392e899..63656a8 100644 --- a/script.py +++ b/script.py @@ -98,11 +98,15 @@ def play_audio(file): sound = sa.WaveObject.from_wave_file(file) play_obj = sound.play() - # TODO: check for sensor data change while play_obj.is_playing(): # Add a small delay to prevent high CPU usage time.sleep(0.1) - load_media() + + for i in range(12): + if mpr121[i].value: + print("Pin {} touched!".format(i)) + load_media(i) + load_media(0) def get_random_file(f): print("getting random file from ") @@ -181,7 +185,7 @@ def load_media(region=None, override=None): cv2.destroyAllWindows() break else: - print("ois the video finished?") + print("is the video finished?") load_media(0) break elif file.endswith(".wav") or file.endswith(".mp3"):