How do I prevent a counter object from looping?

Norbert's icon

I'm using a counter object to help monitor input from a USB device.
When the device sends a signal to inc/decrement the values I want them
to go up/down and counter does this brilliantly. What I can't get
counter to do is STOP once it reaches an upper or lower limit.

I'm sending a 0 or 1 to the second inlet of counter to regulate
direction when values are within a range and that works perfectly to
set UP or DOWN for the counter. However, when I get to a max or min
value and try to *advance further* in that direction the counter loops
back to the opposite extreme and continues counting from there.

What I want is to have counter respond so that once a min or max has
been met it *will not advance* in that direction any more and only be
able to go in the opposite direction. I imagine that this is a common
need but haven't been able to find any patches that use the technique.
Please write if you have any suggestions. Thank you!

::Norbert

Gary Lee Nelson's icon

There are outlets on the counter to tell you when min/max values are
reached. Use them to turn off a gate at the counter's left inlet.

On 7/17/07 5:34 PM, "Norbert Herber" wrote:

> I'm using a counter object to help monitor input from a USB device.
> When the device sends a signal to inc/decrement the values I want them
> to go up/down and counter does this brilliantly. What I can't get
> counter to do is STOP once it reaches an upper or lower limit.
>
> I'm sending a 0 or 1 to the second inlet of counter to regulate
> direction when values are within a range and that works perfectly to
> set UP or DOWN for the counter. However, when I get to a max or min
> value and try to *advance further* in that direction the counter loops
> back to the opposite extreme and continues counting from there.
>
> What I want is to have counter respond so that once a min or max has
> been met it *will not advance* in that direction any more and only be
> able to go in the opposite direction. I imagine that this is a common
> need but haven't been able to find any patches that use the technique.
> Please write if you have any suggestions. Thank you!
>
> ::Norbert

Cheers
Gary Lee Nelson
Oberlin College
www.timara.oberlin.edu/GaryLeeNelson

keithmanlove's icon

> When the device sends a signal to inc/decrement the values I want them
> to go up/down and counter does this brilliantly. What I can't get
> counter to do is STOP once it reaches an upper or lower limit.

just use the 2nd and third outlets to stop the input in some way

> What I want is to have counter respond so that once a min or max has
> been met it *will not advance* in that direction any more and only be
> able to go in the opposite direction.

Sending a 2 to the second inlet gives the "up & down" direction, so
that it starts moving in the other direction when it reaches the min
or max.

Keith

Chris Muir's icon

At 4:34 PM -0500 7/17/07, Norbert Herber wrote:
>What I want is to have counter respond so that once a min or max has
>been met it *will not advance* in that direction any more and only be
>able to go in the opposite direction.

Something like this?:

Max Patch
Copy patch and select New From Clipboard in Max.

--
Chris Muir | "There are many futures and only one status quo.
cbm@well.com | This is why conservatives mostly agree,
http://www.xfade.com | and radicals always argue." - Brian Eno

david@5of4.com's icon

Will sending an "updown" message to the counter do what you need?

Max Patch
Copy patch and select New From Clipboard in Max.

hth
David

---------- Original Message ----------------------------------
From: "Norbert Herber"
Date: Tue, 17 Jul 2007 16:34:58 -0500

>I'm using a counter object to help monitor input from a USB device.
>When the device sends a signal to inc/decrement the values I want them
>to go up/down and counter does this brilliantly. What I can't get
>counter to do is STOP once it reaches an upper or lower limit.
>
>I'm sending a 0 or 1 to the second inlet of counter to regulate
>direction when values are within a range and that works perfectly to
>set UP or DOWN for the counter. However, when I get to a max or min
>value and try to *advance further* in that direction the counter loops
>back to the opposite extreme and continues counting from there.
>
>What I want is to have counter respond so that once a min or max has
>been met it *will not advance* in that direction any more and only be
>able to go in the opposite direction. I imagine that this is a common
>need but haven't been able to find any patches that use the technique.
>Please write if you have any suggestions. Thank you!
>
>::Norbert
>

Need personalized email and website? Look no further. It's easy
with Doteasy $0 Web Hosting! Learn more at www.doteasy.com

david@5of4.com's icon

...or just set the counters direction argument to 2.

Max Patch
Copy patch and select New From Clipboard in Max.

---------- Original Message ----------------------------------
From: "David Morneau"
Reply-To: maxmsp@cycling74.com, david@5of4.com
Date: Tue, 17 Jul 2007 16:47:45 -0700

>Will sending an "updown" message to the counter do what you need?
>
>#P window setfont "Sans Serif" 9.;
>#P window linecount 1;
>#P message 58 83 43 196617 updown;
>#P number 148 141 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
>#P button 140 65 15 0;
>#N counter 1 10;
>#X flags 0 0;
>#P newobj 135 101 68 196617 counter 1 10;
>#P connect 3 0 0 0;
>#P connect 0 0 2 0;
>#P connect 1 0 0 0;
>#P window clipboard copycount 4;
>
>hth
>David
>
>---------- Original Message ----------------------------------
>From: "Norbert Herber"
>Date: Tue, 17 Jul 2007 16:34:58 -0500
>
>>I'm using a counter object to help monitor input from a USB device.
>>When the device sends a signal to inc/decrement the values I want them
>>to go up/down and counter does this brilliantly. What I can't get
>>counter to do is STOP once it reaches an upper or lower limit.
>>
>>I'm sending a 0 or 1 to the second inlet of counter to regulate
>>direction when values are within a range and that works perfectly to
>>set UP or DOWN for the counter. However, when I get to a max or min
>>value and try to *advance further* in that direction the counter loops
>>back to the opposite extreme and continues counting from there.
>>
>>What I want is to have counter respond so that once a min or max has
>>been met it *will not advance* in that direction any more and only be
>>able to go in the opposite direction. I imagine that this is a common
>>need but haven't been able to find any patches that use the technique.
>>Please write if you have any suggestions. Thank you!
>>
>>::Norbert
>>
>
>
>Need personalized email and website? Look no further. It's easy
>with Doteasy $0 Web Hosting! Learn more at www.doteasy.com
>

Need personalized email and website? Look no further. It's easy
with Doteasy $0 Web Hosting! Learn more at www.doteasy.com

Norbert's icon

Chris -- THANK YOU!!! That is doing exactly what I need. I was trying
to use a switch that would trip once a threshold was reached, but the
gates with > and < is much more elegant.

Thanks to others as well. As Don says, "It takes all of us."

::NFH

On 7/17/07, Chris Muir wrote:
> At 4:34 PM -0500 7/17/07, Norbert Herber wrote:
> >What I want is to have counter respond so that once a min or max has
> >been met it *will not advance* in that direction any more and only be
> >able to go in the opposite direction.
>
>
> Something like this?:
>
> #P window setfont "Sans Serif" 12.;
> #P window linecount 1;
> #P comment 282 91 33 196620 Max;
> #P window setfont "Sans Serif" 9.;
> #P hidden message 247 73 14 196617 4;
> #P hidden message 194 72 14 196617 1;
> #P newex 136 246 58 196617 gate;
> #P newex 229 246 58 196617 gate;
> #P window setfont "Sans Serif" 12.;
> #P number 153 90 35 12 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P window setfont "Sans Serif" 9.;
> #P message 28 243 41 196617 min $1;
> #P window setfont "Sans Serif" 12.;
> #P number 246 90 35 12 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P window setfont "Sans Serif" 9.;
> #P message 77 243 42 196617 max $1;
> #P hidden newex 214 49 48 196617 loadbang;
> #P number 115 317 68 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P toggle 229 228 15 0;
> #P toggle 136 228 15 0;
> #P newex 229 209 27 196617
> #P newex 136 209 27 196617 >;
> #N counter;
> #X flags 0 0;
> #P newobj 115 284 66 196617 counter;
> #P window setfont "Sans Serif" 18.;
> #P message 184 181 42 196626 dec;
> #P message 277 181 34 196626 inc;
> #P window setfont "Sans Serif" 12.;
> #P comment 189 92 24 196620 Min;
> #P connect 13 0 12 0;
> #P connect 11 0 10 0;
> #P connect 15 0 3 0;
> #P connect 14 0 3 0;
> #P connect 10 0 3 0;
> #P connect 12 0 3 0;
> #P connect 3 0 8 0;
> #P fasten 8 0 4 0 120 338 320 338 320 161 141 161;
> #P connect 4 0 6 0;
> #P connect 6 0 15 0;
> #P hidden connect 16 0 13 0;
> #P hidden connect 16 0 4 1;
> #P connect 13 0 4 1;
> #P connect 2 0 15 1;
> #P hidden connect 9 0 16 0;
> #P fasten 8 0 5 0 120 338 320 338 320 161 234 161;
> #P connect 5 0 7 0;
> #P connect 7 0 14 0;
> #P hidden connect 17 0 11 0;
> #P connect 11 0 5 1;
> #P hidden connect 9 0 17 0;
> #P connect 1 0 14 1;
> #P window clipboard copycount 19;
>
>
> --
> Chris Muir | "There are many futures and only one status quo.
> cbm@well.com | This is why conservatives mostly agree,
> http://www.xfade.com | and radicals always argue." - Brian Eno
>

Chris Muir's icon

At 8:21 PM -0500 7/17/07, Norbert Herber wrote:
>Chris -- THANK YOU!!! That is doing exactly what I need. I was trying
>to use a switch that would trip once a threshold was reached, but the
>gates with > and < is much more elegant.

You're welcome.

The downside with using the carry and underflow outlets as a couple people suggested is that it's really hard to get your patch in a good state. Counter's carry and underflow outlets are sort of stupid.

-C

--
Chris Muir | "There are many futures and only one status quo.
cbm@well.com | This is why conservatives mostly agree,
http://www.xfade.com | and radicals always argue." - Brian Eno

Roman Thilenius's icon

if i need a one-time counter from 0 to 17 i
usually use something like [substitute 17 0]
where the "0" turns the metro off and resets
the counter.

-110