How to implement counter decrease?

i want when its on 2 then 1 then 0 then 10 ,what patch should i use ?
i want to make something like next and previouse
all the thing is ok , the problem is , when decrease , 5 to 4 to 3 to 2 to 1 then to -1 …, what i want is , the number go back to 10

Oh, good question! I see this asked a lot but this is the first time I’ve looked into it. The magic behind the solution is the modulo operator. It will give you the remainder of a number when it’s divided. E.g. 7 % 3 = 1 (read “seven modulo three”) because 7/3 has a remainder of 1. This is probably how the counter’s “max count” works under the hood - it’s basically just a modulo.

I’m a little surprised the counter doesn’t handle negative values in the way you describe, but you can make your own super-counter that will do it with just a few extra nodes.

The modulo of negative max count will give you the remainder that you need. The result is negative, but you can add 1-maxCount to flip it into the positive range that you want. Then switch the behavior based on if the incoming value is negative or not.

It’s kinda dumb that there’s no input for max count on the counter patch. If there was, you could package this up nicely into a SUPERCOUNTER patch or something cool like that. Instead, you’ll have to make it into a patch that modifies the output of a normal counter.

3 Likes

This is a much simple version. But the increase and decrease input has reverse output.
If you put a pulse on increase, it will deacrease and vice versa.

Just make sure that those values encircled are the same. Those are your Maximum Count.

4 Likes