Update sound sensor
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user