using either a rotory encoder or button press count to change pwm mode

the encoder im using is basically a binary switch that for each of its 32 detent positions generates a bit sequence on its 6 pins one of those pins however im using as the common pin since im intent on using this switch to pull down high state pins from the arduino to in theory avoid the false trigger issue associated with floating input states here is the full grey code table for the encoder
shaft
position
1 0 0 0 1 1 off
2 0 0 1 1 1
3 0 1 1 1 1
4 0 1 0 1 1
5 0 1 0 0 1
6 0 1 1 0 1
7 0 0 1 0 1
8 0 0 0 0 1 hi
9 0 0 0 0 0
10 0 0 1 0 0
11 0 1 1 0 0
12 0 1 0 0 0
13 0 1 0 1 0
14 0 1 1 1 0
15 0 0 1 1 0
16 0 0 0 1 0 med
17 1 0 0 1 0
18 1 0 1 1 0
19 1 1 1 1 0
20 1 1 0 1 0
21 1 1 0 0 0
22 1 1 1 0 0
23 1 0 1 0 0
24 1 0 0 0 0 low
25 1 0 0 0 1
26 1 0 1 0 1
27 1 1 1 0 1
28 1 1 0 0 1
29 1 1 0 1 1
30 1 1 1 1 1
31 1 0 1 1 1
32 1 0 0 1 1 strobe

arduino pin 3 4 5 6 7
encoder pin 4 2 1 3 5