I'm using Mono and the Raspberry Sharp library to try and decode the output of a rotary encoder.
Raspberry sharp: https://github.com/raspberry-sharp/raspberry-sharp-io
Rotary encoder data sheet: http://www.bourns.com/data/global/pdfs/PEC11R.pdf
So far I've tried using the library's PinStatusChanged
event to trigger a simple Console.WriteLine()
when either one of the pins changes value:
private static InputPinConfiguration pinA = ConnectorPin.P1Pin24.Input().PullUp();
private static InputPinConfiguration pinB = ConnectorPin.P1Pin26.Input().PullUp();
static void Main(string[] args)
{
var pinAConnection = new GpioConnection(pinA);
pinAConnection.PinStatusChanged += (sender, eventArgs) =>
{
Console.WriteLine(eventArgs.Enabled.ToString());
};
var pinBConnection = new GpioConnection(pinB);
pinBConnection.PinStatusChanged += (sender, eventArgs) =>
{
Console.WriteLine(eventArgs.Enabled.ToString());
};
}
If I run this on the Pi I can see things happening with the above code. The problem I'm facing is that the Raspberry Sharp library doesn't appear to have functionality for monitoring multiple pins at the same time. To the best of my knowledge, correctly assessing the state of the rotary encoder requires interpreting the values of two of its pins simultaneously. Does anyone have any suggestions as to how to go about this using the Raspberry Sharp library?