I need to have many button switches run from the analog pins. I was thinking of using one pin for multiple switches. For example, running a 3v3 line through a switch to analog pin 0 and a 5v regulated line through a switch to the same pin. Depending on the switch, would the pin record either about 675 or 1023, enabling me to figure out which switch was pressed?
Look here:
http://www.instructables.com/id/SLPCR1LG1BBBV6C/
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1226896251
Thanks muchly. I thought that would work and had been done before.
Hi,
You can actually hook up a whole matrix keypad onto a single analog pin. There must be something on this in the avrfreaks forum. check it out, if not, i will post a link here in sometime.
Cheers,
Pracas
Check this out.
The Microchip application note AN234 has a good overview of saving input and output pins. It covers using resistors and analog pins for polling multiple switches.
It also has some info on multiplexing / charlieplexing to save output pins for driving LEDS, though I've switched over to using external LED drivers for this sort of thing (ex. the Allegro A6276).
That keypad idea is pretty good. I think I'll use some sort of resistor based system, or maybe just use the 3v3 / 5v lines. With all the analog inputs on my duemilanove it should be enough, but it's interesting to realise that with more switches with resistors you could run a whole load of switches from the board.
Just remember that you can have a lot of switches monitored this way if two or more never get pressed at the same time. If this is going to happen then the number of switches is restricted in theory to the number of bits you have in the A/D conversion. In practice I would say the maximum you could achieve is the number of bits minus two or three.