How to detect and handle in your code

For 10-bit ADC, the 8th button generates ADC value between (1±6%)x512, the equivalence of "481-543". If the ADC value had been detected to be "510-518" in the code, the 8th button's supposed to have been pressed.

For 8-bit ADC, the 8th button generates ADC value between (1±6%)x128, the equivalence of "120-136". If the ADC value had been detected to be "124-128" in the code, the 8th button's supposed to have been pressed.