PyRaspBeta

← All practice problems

Raspberry Pi practice problem · Sensors

Noise dose

HardBudget $7Python · gpiozero

A sound sensor (powered from 3.3 V) with its DO on GPIO27 — high while it is loud — and a red LED on GPIO17. Hearing protection cares about the total time spent in noise, not the number of noises. Add up the time DO is high, across all bursts:

  • each time the total passes another whole second, print it — Loud for 1 s, Loud for 2 s, …
  • once the total is over 3 s, light the LED and leave it on.

The test makes noise from 1.0–1.6 s, 2.0–2.8 s, 4.0–5.0 s and 6.0–6.8 s (3.2 s in all). Sample DO at least every 0.05 s.

More in Sensors