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

my apologies im posting this from an iPod touch so its not easy to properly structure these posts.
here is more information on the encoders im using they are 6 pin 32 detent binary state and im using them with pin 1 as gnd and pins 2-6 as the pull down pins for the input of the mega2560 i have the following states chosen for the project
going counterclockwise from detent 32 i am using the following process
on the circuit the following conditions are true encoder pin 1 tied to gnd
digital ins 1,2,3,4,5 of the mega2560 are tied to +5v through a 4.7K sip resistor network
encoder pins 2,3,4,5,6 are tied to the following
digital pin 1 encoder pin 2
digital pin 2 encoder pin 3
digital pin 3 encoder pin 4
digital pin 4 encoder pin 5
digital pin 5 encoder pin 6
32-1 detent ccw = pin 1 tied to pins 3,5,6
32-2 detent ccw = pin 1 tied to pins 3,4,5,6
32-3 detent ccw = pin 1 tied to pins 2,3,4,5,6
32-4 detent ccw = pin 1 tied to pins 2,3,5,6

i need to be able to make a sketch that reads the states of digital pins 1-5 and using a set of defined truth tables for the states of those pins compared to the state of the encoders position preforms the actions i posted above in my initial post