From 4865daa65266e1e337b5b809757ea57c53db719f Mon Sep 17 00:00:00 2001 From: Laurent Date: Sun, 4 Jan 2026 21:14:10 +0100 Subject: [PATCH] Update sound sensor --- rpi/hardware/sound/sound.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/rpi/hardware/sound/sound.py b/rpi/hardware/sound/sound.py index f23625d5..e377d46f 100644 --- a/rpi/hardware/sound/sound.py +++ b/rpi/hardware/sound/sound.py @@ -39,16 +39,17 @@ class SoundReader: self._subscriber(data) def _read(self): - measure_duration = 0.2 - interval = 2 + measure_iteration = 100 + i = 0 while self._running: level = 0 - start = time.time() - while time.time() - start < measure_duration: - if GPIO.input(self._pin): - level += 1 - self._notify(f'{{"soundSensorValue": {level}}}') - time.sleep(interval - measure_duration) + if GPIO.input(self._pin): + level += 1 + if i == measure_iteration: + self._notify(f'{{"soundSensorValue": {level}}}') + i = 0 + i += 1 + time.sleep(0.02) if __name__ == "__main__": sensor = SoundReader(pin=17)