encoder

ivanmason/ecw-digital-contacting-encoder/encoder

No description
encoder
@/encoder
PAport
PBport
UPDpulse
encoder
PA
PB
UPD
CW
CCW
CCWpulse
CWpulse
To use the node in your project you should have the ivanmason/ecw-digital-contacting-encoder library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.

C++ implementation

struct State {
    bool dir;
    bool olda;
    bool oldb;
};

{{ GENERATED_CODE }}

void evaluate(Context ctx) {
    
    auto state = getState(ctx);
    auto portA = getValue<input_PA>(ctx);
    auto portB = getValue<input_PB>(ctx);
    auto ina = digitalRead(portA);
    auto inb = digitalRead(portB);


   if (isSettingUp()) {
        // Remember the initial (on boot) encoder state
       state->dir = true;
       state->olda = ina;
       state->oldb = inb;
       return;
   }

    if(state->olda != ina || state->oldb != inb){

       if(state->olda != inb ){
           state->dir = false;
           emitValue<output_CCW>(ctx, 1);
          }
        else{
           state->dir = true;
           emitValue<output_CW>(ctx, 1);
        }
    }

   state->olda = ina;
   state->oldb = inb;
}