I am trying to read the pwm signal from a digital encoder I got out of a mouse should I use PulseIn or analogRead. Please let me know the best way to do this. Thanks.
I am trying to read the pwm signal from a digital encoder I got out of a mouse should I use PulseIn or analogRead. Please let me know the best way to do this. Thanks.
My money would be om pulseIn(), but you might need to monitor more than one pin to determine direction. See for example DASF006380.pdf
I would probably not use pulseIn either. You need to count state changes, so busy monitoring or attachInterrupt() would match better.
It is only one direction and in not farmiliar withattachInterrupt() could you please explain or is it in the .pdf?
The pdf was just a random example - i have no idea what component you are using
This is how i would hook up the wheel decoder to test it:
// pin change interrupt example
// attach wheel input on digital pin 2
// not all pin's are able to interrupt on change, check documentation
// these are for Arduino UNO
#define interruptPin2 0
#define interruptPin3 1
volatile int wheelPos = 0;
void setup()
{
Serial.begin(9600);
attachInterrupt(interruptPin2,moved,CHANGE);
}
void loop()
{
Serial.print("Wheel position: ");
Serial.println(wheelPos,DEC);
// do other stuff
delay(1000);
}
// everytime the wheel pin changes we call this function
void moved()
{
// do simple and quick operations within the interrupt call
wheelPos++;
}
Thanks ill give this a try!
Hi,
Are you using a encoder of a Mouse...that's great. would you please share the details of project. Even i will love to give it a try.
Thanks.
Hi Christer, remember me from STK?
Regards
Andy
Tel.+49-(0)6008-2580173 Haus/House
Mobile.+49-(0)163-2887669