Holmes4 and PeterH firstly thanks for your interest,
My older problem was type of my encoder.
http://robotus.net/wp-content/uploads/2012/07/manyetik-encoder-forceup.jpg
This is not usual rotary encoder. So, I tried a lot of example in Arduino Rotary Encoder Library. One of them was this code below.
/* read a rotary encoder with interrupts
Encoder hooked up with common to GROUND,
encoder0PinA to pin 2, encoder0PinB to pin 4 (or pin 3 see below)
it doesn't matter which encoder pin you use for A or B
uses Arduino pullups on A & B channel outputs
turning on the pullups saves having to hook up resistors
to the A & B channel outputs
*/
#define encoder0PinA 2
#define encoder0PinB 4
volatile unsigned int encoder0Pos = 0;
void setup() {
pinMode(encoder0PinA, INPUT);
digitalWrite(encoder0PinA, HIGH); // turn on pullup resistor
pinMode(encoder0PinB, INPUT);
digitalWrite(encoder0PinB, HIGH); // turn on pullup resistor
attachInterrupt(0, doEncoder, CHANGE); // encoder pin on interrupt 0 - pin 2
Serial.begin (9600);
Serial.println("start"); // a personal quirk
}
void loop(){
// do some stuff here - the joy of interrupts is that they take care of themselves
}
void doEncoder() {
/* If pinA and pinB are both high or both low, it is spinning
* forward. If they're different, it's going backward.
*
* For more information on speeding up this process, see
* [Reference/PortManipulation], specifically the PIND register.
*/
if (digitalRead(encoder0PinA) == digitalRead(encoder0PinB)) {
encoder0Pos++;
} else {
encoder0Pos--;
}
Serial.println (encoder0Pos, DEC);
}
When I use this code, I had confused but a kind of order numeric results like that;
-1
0
1
0
-1
0
1
0
-1
...
It seems like logical step like,
http://upload.wikimedia.org/wikipedia/en/6/68/Quadrature_Diagram.svg
I couldn't find anything to solve the problem, so I decieded to use only one channel.
And It works! But,
And than, new problem was I couldn't write the "encoder0Pos" to LCD 16x2 if I identify like "volatile unsigned int encoder0Pos = 0;".
Altough, I try a few type of conversation such as "itoa(x,encoder0Pos,10)" "itoa(x,encoder0Pos,16)" , it was not work.
So, I use only "int encoder0Pos = 0;". This is why I don't use volatile.
I hope I explained problems understandable.
Now I got only about %20 missing pulses per revolation, thanks to Paul. But it isn't acceptable mistake.
Thank a lot again.
Yours faithfully