counter2_init_start

cyclic up/down counter with initial start value
Author: Djeremaille
License:
Github: djrm/logic/counter2_init_start.axo

Inlets

bool32.rising increment trigger

bool32.rising decrement trigger

bool32.rising reset

Outlets

int32 output

bool32.pulse carry pulse

Parameters

int32 maximum

int32 init

Declaration
int ntrig;
int rtrig;
int dtrig;
int count;
int somme;
Init
count = 0;
ntrig = 0;
dtrig = 0;
rtrig = 0;
somme = 0;
Control Rate
outlet_c = 0;
somme = count + param_init;
if ((inlet_inc > 0) && !ntrig) {

  count++;
  if (somme >= param_maximum) {
    count = -(param_init);
    outlet_c = 1;
  }
  ntrig = 1;
} else if (!(inlet_inc > 0))
  ntrig = 0;
if ((inlet_dec > 0) && !dtrig) {

  count--;
  if (somme < 1) {
    count = param_maximum - param_init;
    outlet_c = 1;
  }
  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 = somme;

Privacy

© 2024 Zrna Research