How to get 180 optical encoder motor's encoder data?


#1

Hello everyone,
I have a big trouble in my project. I want to use Arduino Mega 2560 and motor driver L298N to control my 180 optical encoder motor just like the picture showed below.


The 180 optical encoder motor is this.
http://store.makeblock.com/180-optical-encoder-motor
And the Arduino code

And the result

Is it the right way to get encoder data or not?
Please teach me how to use DIR and INT pin to get the position of the motor, thank you.


#2