Is there any way I can get 9 buttons to toggle on an analog pin? Each button has its own function (controlling different laser shows) and when you press one it should turn off the last one. I've made a momentary push button work with the analog pin but I need them to be toggleable. I've ran out of pins on an Arduino Mega
If you had a pull-up resistor on the analog pin and all the 'A' terminals of buttons connected to the pin, you could use different resistors on each of the 'B' terminals of the switches to GND. When a button is pressed, the voltage divider created by the pull-up and the resistor to ground will present a voltage to the analog pin unique to that button.
You just need to select the resistors to give decent "windows" for each button to reduce the chance of overlap when things like the tolerance of the resistors is taken into account.
An analog read of the pin will return a value between 0 and 1023. Choose your resistor values to return a voltage giving nominal A/D counts of (for example)
And of course you can always add more digital GPIO pins by using chips like the MCP23017 which only require the two I2C pins. Far simpler than analog ladders.