countersat2

saturating up/down counter
Author: Johannes Taelman
License: BSD
Github: logic/countersat2.axo

Inlets

bool32.rising increment trigger

bool32.rising decrement trigger

bool32.rising reset

Outlets

int32 output

Parameters

int32 maximum

Declaration
int ntrig;
int rtrig;
int dtrig;
int count;
Init
count = 0;
ntrig = 0;
dtrig = 0;
rtrig = 0;
Control Rate
if ((inlet_inc > 0) && !ntrig) {
  count++;
  if (count >= param_maximum) {
    count = param_maximum - 1;
  }
  ntrig = 1;
} else if (!(inlet_inc > 0))
  ntrig = 0;
if ((inlet_dec > 0) && !dtrig) {
  count--;
  if (count < 0) {
    count = 0;
  }
  dtrig = 1;
} else if (!(inlet_dec > 0))
  dtrig = 0;
if ((inlet_r > 0) && !rtrig) {
  count = 0;
  rtrig = 1;
} else if (!(inlet_r > 0))
  rtrig = 0;
outlet_o = count;

Privacy

© 2024 Zrna Research