Rotary Encoder Bipolar

Reads a rotary encoder trig - trigger input on rising edge dir - dir>0=clockwise, dir<0=anti-clockwise max value represents both negative and possitive, zero always being center.
Author: Gavin
License: BSD
Github: gav/rot_enc/Rotary Encoder Bipolar.axo

Inlets

bool32 mom

bool32.rising increment trigger

bool32.rising decrement trigger

Outlets

int32 output

bool32 b

Parameters

int32 max

int32 preset

Declaration
int val;
int encoderPos;
int encoderLast;
int n;
int change;
Init
encoderPos = 0;
encoderLast = 0;
n = 0;
val = 0;
change = 0;
Control Rate
change = 0;
n = inlet_trig;
if ((encoderLast == 0) && (n > 0)) {
  change = 1;
  if (inlet_dir == 0) {
    if (param_preset + encoderPos > (param_max * -1)) {
      encoderPos = encoderPos - 1;
    }
  } else {
    if (param_preset + encoderPos < param_max) {
      encoderPos = encoderPos + 1;
    }
  }
}
encoderLast = n;
if (val == inlet_mom) {
  val = !inlet_mom;
}
if (change = 1) {
  outlet_o = param_preset + encoderPos;
}
outlet_b = val;

Privacy

© 2024 Zrna Research