Read N samples, store in a ring buffer, output a moving average.
Pull everything together — the classic embedded "sample → buffer → filter" pipeline.
```c
#define WIN 8
static int samples[WIN];
static int idx = 0;
static int filled = 0;
void add_sample(int s); // store next sample, advance idx with wrap
int moving_avg(void); // average of valid samples (0 if none yet)
```
Rules:
- `add_sample` writes to `samples[idx]`, then `idx = (idx + 1) % WIN`, and grows `filled` until it hits WIN.
- `moving_avg` returns 0 if filled == 0; otherwise sum of the first `filled` slots / filled.
Reference: front-end of every digital filter (CPES / Embedded Systems & IoT curricula).
Sign in to save your code and track progress across devices.