Robin2:
You have not described what you are trying to create. It is much easier to give useful advice when we know what the project is.
You have not provided links to the datasheets
...R
Encoder
Motor
Driver
My project is to create a robotic hand.
I will send a signal to the robotic hand. After the robotic hand received the signal, based on the position set on the code, the motor will rotate at that certain position.
Why have you set the enable pin to pinmode INPUT? Don't you think that should be an OUTPUT since you are constantly writing to that pin?
Also, what do you expect this configuration to do once the motor has achieved the desired position? What is going to maintain that position? The motor driver brake function only provides a limited ability to slow the motor down, it does not lock the motor. Once the motor has stopped the brake function is useless. So what will keep your hand at its new position once you have cut power to the motor?
IMHO a stepper motor would be a better solution since it has positional control and can easily hold a position.
ettexx:
My project is to create a robotic hand.
I will send a signal to the robotic hand. After the robotic hand received the signal, based on the position set on the code, the motor will rotate at that certain position.
It would be useful to see a diagram of how the motor links to the hand.
Also, hands usually have several moving parts. Are you planning to have other motors? If so what kind? Reading an encoder without missing pulses is a lot of work for an Arduino and I doubt if it could successfully read several encoders.
On top of all that there is what @Due_unto has said about holding position. Stepper motors would probably be better than a simple DC motor. And whether using a DC motor or a stepper motor you will need some means (such as a limit switch) to determine the HOME or ZERO position.
With all that in mind a servo might be best of all because they have absolute position control and all their electronics in a neat package.
The usual way to read the encoder is by connecting its pulse outputs to two Arduino interrupt pins. When an interrupt is triggered if you read the state of the other pin you can tell which direction the shaft is rotating, You could probably get away with just using one interrupt as your program should already know which direction the motor is moving. I reckon you will get lots of examples if you Google arduino motor encoder.