Using detachInterrupt or attachInterrupt with encoder.h library

I have been using a sketch that moves linear actuators on a moving vehicle, but the vibrations cause false readings on the hall effect encoders.

I was thinking of detaching the interrupt they are connected to to prevent the erroneous readings until I want the interrupts to be counted.

I have not found an example of doing this with the encoder.h library. Any ideas?

Using an Arduino Mega 2560

[code]

#include <Encoder.h>

Encoder leftHall(18, 20);
Encoder rightHall(19, 21);

[/code]

Why don't you just set the pin to output temporarily? Of course you have to be careful to produce no short circuit but if you do it suitable for your circuitry (which you're hiding from us) it may work.

It would be even easier to just have your code ignore updates to the encoder value until you're interested in them.

Thanks gfvalvo - I was thinking along the same lines, but before I re-coded the sections of my sketch I thought I should at least ask.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.