Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for encoders with 3 states #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions libraries/Rotary/Rotary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,32 @@ const unsigned char ttable[6][4] = {
// R_CCW_BEGIN_M
{R_START_M, R_CCW_BEGIN_M, R_START_M, R_START | DIR_CCW},
};
#elif defined(TRISTATE)
// Encoder with three states: 00, 10, 11
// CW rotation down, CCW rotation up
// 00 CCW_FINAL
// 10 CCW_BEGIN
// 11 R_START <-- Dent
// 00 CW_BEGIN
// 10 CW_FINAL
#define R_CW_FINAL 0x1
#define R_CW_BEGIN 0x2
#define R_CCW_BEGIN 0x3
#define R_CCW_FINAL 0x4

const unsigned char ttable[5][4] = {
// R_START
{ R_CW_BEGIN, R_START, R_CCW_BEGIN, R_START },
// R_CW_FINAL
{ R_CW_BEGIN, R_START, R_CW_FINAL, R_START | DIR_CW},
// R_CW_BEGIN
{ R_CW_BEGIN, R_START, R_CW_FINAL, R_START},
// R_CCW_BEGIN
{ R_CCW_FINAL, R_START, R_CCW_BEGIN, R_START},
// R_CCW_FINAL
{ R_CCW_FINAL, R_START, R_CCW_BEGIN, R_START | DIR_CCW},
};

#else
// Use the full-step state table (emits a code at 00 only)
#define R_CW_FINAL 0x1
Expand Down
3 changes: 3 additions & 0 deletions libraries/Rotary/Rotary.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
// Enable this to emit codes twice per step.
//#define HALF_STEP

// Enable this if your encoder has only 3 states.
//#define TRISTATE

// Enable weak pullups
#define ENABLE_PULLUPS

Expand Down