setting an adress


im thinking of using 10 DILswitches to set adresses between 0-1024) in project I´m working on but i´m looking for a way to not use 10 pins on the arduino. do you guys know if there is some kind of integrated circuit that does the jobb for me.

You could read the address bits using a parallel-in, serial-out shift register. In TTL, there’s the 74HC165 and in CMOS there’s the CD4021. The CD4021 chip was used in the Nintendo game pad and in the Super Nintendo, so any code that you can find for reading those will work for your switches.

Sorry to be picky, but to set addresses 0..1024, you'd need eleven switches.

Save the address in EEPROM? Use a custom sketch to program the address. Zero pins used.


There is code in this thread that uses three switches to set hours, minutes and seconds that could be easily modified to for your application.

You can do as kg4wsv suggests and save the value in eeprom

If you need to input a value, regardless of the range, you can use one input pin, if you handle the input through software. For example, you may have just one push button. As long as you hold it down, a value will increment. As soon as you reached the desired value, you release the button. You can do similarly with a remote control, "connected" to an IR receiver.

Another way (just popped up) would be to use a digital input with a fine, multi-revolution potentiometer. This last idea is just theory, I have never tried it.

Anyway, in both cases you would need some sort of feedback (basically a sort of display), to see when you reached the desired value.

In principle, to get a 0-1023 (10-bit) value into a sketch, you could set up a potentiometer on one of the analog inputs. If you actually try it, you'll find that it's much too difficult to set an exact value using a pot, and there is enough noise in the system that the ADC output jumps up and down by a few counts, even when you're not turning the pot. You could probably get 0-255 (8 bits) if you were careful with the pot (choose a high-quality, expensive one), but a digital solution is probably the best way!