Rot Enc Value

Reads a rotary encoder trig - trigger input on rising edge dir - dir>0=clockwise, dir<0=anti-clockwise
Author: Gavin
License: BSD
Github: gav/rot_enc/Rot Enc Value.axo

Inlets

int32 value

bool32.rising increment trigger

bool32.rising decrement trigger

bool32 mom

Outlets

bool32 b

bool32 a

int32 output

Parameters

int32 value

int32 min

int32 max

int32 preset

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

Privacy

© 2024 Zrna Research