Rotary Encoder

Reads a rotary encoder trig - trigger input on rising edge dir - dir>0=clockwise, dir<0=anti-clockwise Requires two digital Axoloti GPIO inputs set to "pullup"
Author: Gavin
License: BSD
Github: gav/rot_enc/Rotary Encoder Basic.axo

Inlets

bool32.rising increment trigger

bool32.rising decrement trigger

Outlets

int32 output

Declaration
int encoderPos;
int encoderLast;
int inval;
Init
encoderPos = 0;
encoderLast = 0;
inval = 0;
Control Rate
inval = inlet_trig;
if ((encoderLast == 0) && (inval > 0)) {
  if (inlet_dir == 0) {
    encoderPos--;
  } else {
    encoderPos++;
  }
}
encoderLast = inval;
outlet_o = encoderPos;

Privacy

© 2024 Zrna Research