hi,
Thanks for the reply. Really appreciate the help.
This is the encoder i'm using.
https://www.sparkfun.com/products/11102I followed your link and used this code. I was able to hook everything up and have it output to serial. How can I calibrate or modify this sketch so that one revolution of the shaft would display 100.00. if I turn CCW 1/4 turn it would display 75.00. There would be a dial on the encoder shaft that would be marked out evenly 1 - 100. I also want to use the high resolution of this encoder to indicate the dial position when it is between a number ie: 12.6572.
Once I can get it working and display it on the serial monitor I would like to have the encoder ouput to my lcd 1620a. I have no idea how to wire this to my adruino mega 2560 board, or how to include the lcd 1620a in the code.
Bill
/* Rotary encoder with attachInterrupt
Counts pulses from an incremental encoder and put the result in variable counter.
Taking also into account the direction and counts down when the rotor rotates in
the other direction.
This code is used attachInterrupt 0 and 1 which are pins 2 and 3 moust Arduino.
For more information about attachInterrupt see:
http://arduino.cc/en/Reference/AttachInterrupt created 2014
by Ben-Tommy Eriksen
https://github.com/BenTommyE/BenRotaryEncoder */
// Encoder connect to digitalpin 2 and 3 on the Arduino.
volatile unsigned int counter = 0; //This variable will increase or decrease depending on the rotation of encoder
void setup() {
Serial.begin (9600);
//Setting up interrupt
//A rising pulse from encodenren activated ai0(). AttachInterrupt 0 is DigitalPin nr 2 on moust Arduino.
attachInterrupt(0, ai0, RISING);
//B rising pulse from encodenren activated ai1(). AttachInterrupt 1 is DigitalPin nr 3 on moust Arduino.
attachInterrupt(1, ai1, RISING);
}
void loop() {
// Send the value of counter
Serial.println (counter);
}
void ai0() {
// ai0 is activated if DigitalPin nr 2 is going from LOW to HIGH
// Check pin 3 to determine the direction
if(digitalRead(3)==LOW) {
counter++;
}else{
counter--;
}
}
void ai1() {
// ai0 is activated if DigitalPin nr 3 is going from LOW to HIGH
// Check with pin 2 to determine the direction
if(digitalRead(2)==LOW) {
counter--;
}else{
counter++;
}
}