I was working on a program and needed the user to be able to select from over 12 choices of pre-recorded patters.

I chose to use a absolute position rotary encoder that had 16 detents.

The particular one I chose was the Alps EC18AGB20401 Unfortunately the code that it returned was not quite binary so I had to use a look up table to go from 0-15.

int rotLUT[]={0,1,15,14,3,2,4,5,11,10,12,13,8,9,7,6};

Based on this table:

# #0 pin pin pin pin decodes as
4 3 2 1 dec
4 3 2 1 dec
1 0 0 0 0 0 0
2 1 0 0 0 1 1 clockwise
3 2 0 1 0 1 5
4 3 0 1 0 0 4
5 4 0 1 1 0 6
6 5 0 1 1 1 7
7 6 1 1 1 1 15
8 7 1 1 1 0 14
9 8 1 1 0 0 12
10 9 1 1 0 1 13
11 10 1 0 0 1 9
12 11 1 0 0 0 8
13 12 1 0 1 0 10
14 13 1 0 1 1 11
15 14 0 0 1 1 3
16 15 0 0 1 0 2

 

(more…)