|
Treehopper C# API
|
Quadrature rotary encoder More...
Classes | |
| class | PositionChangedEventArgs |
| Rotary encoder position changed event arguments More... | |
Public Member Functions | |
| delegate void | PositionChangedDelegate (object sender, PositionChangedEventArgs e) |
| Rotary encoder position changed delegate More... | |
| RotaryEncoder (DigitalIn a, DigitalIn b, int stepsPerTick=1) | |
| Construct a new RotaryEncoder from two digital inputs More... | |
| void | Dispose () |
Properties | |
| long | Position [get, set] |
| Gets or sets the Position counter. More... | |
| long | MaxValue = long.MaxValue [get, set] |
| The maximum value this encoder should report More... | |
| long | MinValue = long.MinValue [get, set] |
| The minimum value this encoder should report More... | |
Events | |
| PositionChangedDelegate | PositionChanged |
| Fires whenever the position has changed More... | |
| PropertyChangedEventHandler | PropertyChanged |
| Fires whenever the position has changed More... | |
Quadrature rotary encoder
This class is designed to interface with standard, two-channel quadrature-style incremental rotary encoders. These are often used as infinite-turn knobs for human interfaces, motor feedback, measuring wheels, and other rotary/linear motion measurement applications.
If you are using an encoder with an detent, you can set the stepsPerTick parameter to match your encoder so that Position will increment/decrement for each "click" (for many encoders, a value of 4 is correct). For maximum resolution, leave at 1.
This class makes use of DigitalIn's DigitalIn.DigitalValueChanged event. If you're attaching the encoder to an I2c or SPI I/O expander or shift register, make sure your driver is sampling these pins often.
Because the inputs are sampled over USB by the host API, only low to moderate-speed applications are supported; while Treehopper has been tested at input speeds in the 5-10 kHz range, the nondeterministic nature of Treehopper means it is unlikely that this class will work reliably above 500-1000 Hz, and will occasionally miss clicks.
While earlier versions of this library used a 32-signed Position value, this would overflow after less than 25 days with a 1 kHz input signal, which could be problematic for some use cases. As such, this is now stored as a long (64-bit) signed value. With a 1 kHz signal, this will overflow after approximately 292 million years, which should be sufficient for most users.
| RotaryEncoder | ( | DigitalIn | a, |
| DigitalIn | b, | ||
| int | stepsPerTick = 1 |
||
| ) |
Construct a new RotaryEncoder from two digital inputs
| a | A channel input |
| b | B channel input |
| stepsPerTick | The number of steps to count as one "tick" |
| delegate void PositionChangedDelegate | ( | object | sender, |
| PositionChangedEventArgs | e | ||
| ) |
Rotary encoder position changed delegate
| sender | The RotaryEncoder where this message originated from |
| e | The EventArgs this RotaryEncoder generated |
| void Dispose | ( | ) |
|
getset |
Gets or sets the Position counter.
|
getset |
The maximum value this encoder should report
|
getset |
The minimum value this encoder should report
| PositionChangedDelegate PositionChanged |
Fires whenever the position has changed
| PropertyChangedEventHandler PropertyChanged |
Fires whenever the position has changed