Skip to content

Latest commit

 

History

History
99 lines (66 loc) · 4.71 KB

RotaryEnc.md

File metadata and controls

99 lines (66 loc) · 4.71 KB

P2 Rotary Encoder Spin2 Object

A reusable object written in spin2 for reading the rotary encoder with the push button feature. This object features reading of rotation distance and velocity while the button press logic detects single and double-clicks.

Project Maintenance

License

Table of Contents

On this Page:

Additional pages:

The Hardware

This object support the standard Parallax Rotary Encoder.

This device is connected by 3 signal wires, Vcc and ground.

The driver runs a task in a single Cog which continuously monitors the rotation and button presses. The driver provides the following readings from the attached hardware:

  • Rotational distance
  • Rotational Scaled distance (distance x velocity x scale value)
  • Rotational velocity
  • Button presses
  • For each button press, if it is a single our double-press

The Rotary Encoder object PUBLIC Interface

The object isp_quadEncWBtn_sp.spin2 when first started fires a separate monitoring task in a Spin Cog. When you read the values you are reading the latest stored values written by the monitoring task. The object provides the following methods for starting up, tearing down and accessing the values read from the device:

OBJECT Interface Description
>--- CONTROL
PUB start(pnEnc0, pnEnc1, pnBtn)
Start the sensing Cog using the given pins
PUB stop()
Stop the sensing Cog, clear and float the pins used.
PUB setScale(scaleValue)
Set encoder distance scaling to {scaleValue} [Default: 4]
PUB getScale() : scaleValue
Return encoder distance {scaleValue}
>--- SENSING
PUB isButtonPressed() : bIsPressed, bIsDouble
Return {bIsPressed} - T/F where T means button was pressed
and {bIsDouble} - T/F where T means the press was a double press
PUB position() : currPosn
Return {currRate} the current quadEncoder steps since last rotation N where N=[0-n]
PUB positionScaled() : currScaledPosn
Return scaled value for current quadEncoder position N where N=[-n < 0 < n]
AFFECTED BY: setScale(scaleValue)
PUB rate() : currRate
Return {currPosn} the current quadEncoder position N where N=[-n < 0 < n]
PUB positionRate() : currPosn, currRate
Return {currPosn} the current quadEncoder position N where N=[-n < 0 < n]
and {currRate} the current quadEncoder steps since last rotation N where N=[0-n]

NOTE: this object uses 4 smart pins for the quad position decoding. Two connected to the rotary encoder which track current position, while two additional pins (at lower pin number -1 -and -2, are connected to the same two inputs) which track the velocity of the rotation. The 5th pin then senses the button press events.

The Object Source Code

The following files comprise our driver source code:

Filename Purpose Description
Driver FILEs
isp_quadEncWBtn_sp.spin2 DRIVER the Rotary Encoder Driver object using smartpins

If you like my work and/or this has helped you in some way then feel free to help me out for a couple of ☕'s or 🍕 slices!

coffee    -OR-    PatreonPatreon.com/IronSheep


Disclaimer and Legal

Parallax, Propeller Spin, and the Parallax and Propeller Hat logos are trademarks of Parallax Inc., dba Parallax Semiconductor

This project is a community project not for commercial use.

This project is in no way affiliated with, authorized, maintained, sponsored or endorsed by Parallax Inc., dba Parallax Semiconductor or any of its affiliates or subsidiaries.


License

Licensed under the MIT License.

Follow these links for more information: