A/D value to 7 segments - Volume Control

Why not simply
return trunc(val / 1000);

I still suspect that you don't understand hysteresis and running average :frowning: