buttonFunctions

Multifunction momentary button to toggled boolean. 4 "short" outputs: depending on how many times you click the button within the specified time, will it switch one of the "short" outputs, unless the button is held for longer then the "time" setting. "long" output toggles when button has been pressed longer then the "time" setting EXCEPT if it's held longer then twice the "time" setting. "verylong" output toggles when button has been pressed longer then twice the "time" setting. "count" outputs the krate counter, so you can better see the timing-setting that you need. The count only gets reset if the button is pressed while the counter is at max. "clicks" outputs the amount of times the button has been pressed before count reaches the "time" value. "update" sends a trigger out when the counter reaches it's max while the button is released. This is the same moment the short and long outputs are updated. "loopupdate" send a trigger out when the counter restarts (as long as you hold the button down, the counter will loop and this will thus create repeating triggers each time the counter is at zero.)
Author: Remco van der Most
License: BSD
Github: sss/ctrl/buttonFunctions.axo

Inlets

bool32.rising button

Outlets

bool32.pulse update

bool32.pulse loopupdate

bool32 short1

bool32 short2

bool32 short3

bool32 short4

bool32 long

bool32 verylong

int32 count

int32 clicks

Parameters

int32 time

Declaration
int32_t count;
int32_t held;
int32_t Held;
int hold1;
int hold2;
int preprint;
int prevprint;
int print;
int Clicks;
int clicks;
int trig;
int ttrig;
int HOLD;
int prevtrig;
int Short1;
int Short2;
int Short3;
int Short4;
Control Rate
if (inlet_button > 0) {
  held += 1;
  Held = held;
} else {
  held = 0;
}
count += 1;
if ((inlet_button > 0) && (count >= param_time)) {
  count = 0;
}
count = count > param_time ? param_time : count;

// print when end is reached
if ((count >= param_time) && (!(ttrig))) {
  Clicks = clicks;
  clicks = 0;
  if (Held >= param_time) {
    if (Held < (param_time << 1))
      hold1 = hold1 > 0 ? 0 : 1;
    if (Held >= (param_time << 1))
      hold2 = hold2 > 0 ? 0 : 1;
  } else if (Clicks == 1) {
    Short1 = Short1 > 0 ? 0 : 1;
  }
  if (Clicks == 2) {
    Short2 = Short2 > 0 ? 0 : 1;
  }
  if (Clicks == 3) {
    Short3 = Short3 > 0 ? 0 : 1;
  }
  if (Clicks >= 4) {
    Short4 = Short4 > 0 ? 0 : 1;
  }

  ttrig = 1;
} else if (count < param_time) {
  ttrig = 0;
}

if ((count < param_time) && (!(trig)) && (inlet_button > 0)) {
  clicks += 1;
  trig = 1;
} else if (inlet_button == 0) {
  trig = 0;
}

outlet_short1 = Short1;
outlet_short2 = Short2;
outlet_short3 = Short3;
outlet_short4 = Short4;
outlet_long = hold1;
outlet_verylong = hold2;
outlet_count = count;
outlet_clicks = Clicks;
outlet_update = ttrig;
outlet_loopupdate = count == 0 ? 1 : 0;
prevtrig = ttrig;

Privacy

© 2024 Zrna Research