Rotary Encoder - Anlogue or Digital Pin?

I am using a potentiometer at the moment to select 4 states of a menu, but I'd like a more postive feel as the user twists the knob. The trouble is I only have 1 digital pin left available but all of the anlogue pins.

I was thinking of using a rotary encoder but the code looks very complicated vs what I'm using for the potentiometer. I could just do with some general advice, how to make the selection more postive using whatever method with the remaining pins I have. TIA!

You will need 2 pins as I recall D14 is A0, D15 is A1 etc

I looked into this quite recently. Your options are:

  1. Replace your pot with a 4-way rotary switch wired up so it's like a quantised pot. So your switch has four poles P1-P4 and a central throw P0. You wire equal value resistors (eg 10k) between neighbouring poles (eg 10k between P1 and P2, 10k between P2 and P3 etc), A1 to +V and A4 to ground. The central throw is equavelent to the wiper in a pot, just now you have quantised resistance steps.

  2. You get a 2 bit gray code rotary encoder that produces a binary code output on two digital ins. Position 1 will be 00, position 2 01, position 3 10 and position 4 11. It does however require sqrt(n) number of digital inputs, where n is the number of positions.

I think 1. is the best option, that way you can have up to six pots controlling different things simultaneously, it's pretty cheap and bombproof to implement. And as the analogue input pins are 10bit you could in theory have 1024 different positions (don't forget component tolerance though).

Thanks, Option 1 does sound good. Will all rotary switches have a physical feel of clicking between each section?

The trouble is I only have 1 digital pin left available but all of the anlogue pins.

So you actually have seven digital pins left. The use of the term 'anlogue' by the Arduino creators is a red herring. [u]All[/u] of the I/O (input-output) pins on the ATmega328 chips serve dual purposes. One of the optional uses for six of the pins (the ones called analog or analogue by the Arduino creators) is to connect to the internal Analog-to-Digital converter. The default configuration of these pins when the device comes out of reset is for normal I/O, just like all of the 'digital' pins.

What 'mmcp42' was trying to tell you in reply #1 is that the A0 pin can be considered and used as D14, the A1 pin can be considered and used as D15, etc.

Don

Thanks for all the info.

So there is actually 17 digital pins we can use? If thats the case I can do away with the turning menu all together.

indeed sorry my post should have been clearer you can indeed make the analog pins into digital pins!

KE7GKP:

Will all rotary switches have a physical feel of clicking between each section?

Yes, but...

If you have a menu, it is not clear why you need a rotary switch with the four selections (and conversely, if you have a rotary switch to select the options, it isn't clear why you need a menu? If you have more than four things in the menu, then it isn't clear how you can use a rotary switch?

So in some pseudo code like this:

Postion 1 = Menu 1
Postion 2 = Menu 2
Postion 3 = Menu 3
Postion 4 = Menu 4

if(Postion = 1){

button 1 = alpha();
button 2 = beta();
button 3 = charlie();
button 4 = gamma();
}

if(Postion = 2){

button 1 = fun1();
button 2 = fun2();
button 3 = fun3();
button 4 = fun4();
}

There is nothing special needed to do to use the A0-6 pins as digital pins, they are set like that from the get go?

So there is actually 17 digital pins we can use? If thats the case I can do away with the turning menu all together.

Actually there are 19 if you are not using the serial monitor.

Don

Chems: Thanks, Option 1 does sound good. Will all rotary switches have a physical feel of clicking between each section?

most of the rotary encoders I have encountered are very clicky

There is nothing special needed to do to use the A0-6 pins as digital pins, they are set like that from the get go?

You just have to know they are numbered 14..19 for use with pinMode/digitalRead/digitalWrite

You just have to know they are numbered 14..19 for use with pinMode/digitalRead/digitalWrite

You just need to know that they are called A0, A1, A2 etc, and you're OK to use them for either.