Stable-read a noisy button with N consecutive samples.
Mechanical buttons bounce. Implement:
```c
int debounce(int sample); // returns the stable level (0/1)
```
Use static counters. The level only changes after `THRESHOLD` (e.g. 4) consecutive identical samples.
Pattern:
- static int level, count;
- if (sample == level) count = 0;
- else if (++count >= THRESHOLD) { level = sample; count = 0; }
- return level;Sign in to save your code and track progress across devices.