control a stepper motor with rotary encodeer

CS pin 2
#define A_PHASE 2

You have a pin conflict there.

Combining codes
More combining codes

Give it a try and, if you have trouble, post the combined code and we can help.