Smoothing example script (phyduino.py) Prints a running average of the last 10 readings of A0, which steadies a noisy signal. Each new reading replaces the oldest one. For averaging done by the board itself, see Analog Averaging.
- Wiring
- A potentiometer wiper or sensor on A0 (0-3.3 V).
import time
import phyduino as mcu
NUM_READINGS = 10
readings = [0] * NUM_READINGS
index = 0
total = 0
while True:
total -= readings[index]
readings[index] = mcu.analog_read("A0")
total += readings[index]
index = (index + 1) % NUM_READINGS
print(total // NUM_READINGS)
time.sleep_ms(1)