two number boxes controlling 4 toggles

Josef Rebbe's icon

Hallo.

I'm quite new in Max and need a little help with the following:

I have two number boxes. The first one (X) has a range of -62 till 63 and the second one (Y) from -116 till 117.
According to the 8 possible movements of the numbers listed below (increasing or decreasing), the 4 toggles have to behave like described.

If X increase toggle 2 and 4 are ON
If X decrease toggle 1 and 3 are ON
If Y increase toggle 1 and 2 are ON
If Y decrease toggle 3 and 4 are ON
If X and Y increase toggle 2 is ON
If X and Y decrease toggle 3 is ON
If X decrease and Y increase toggle 1 is ON
If X increase and Y decrease toggle 4 is ON
If there is no movement for more than 0.5 seconds all toggles should be off.

Is there something like an if then function that I could use?

Any help is much appreciated.
Josef

mattyo's icon

Hi Josef,

here is a rough-in on one approach to one channel -- there are a million ways to do things like this in Max. I have minimal comments, so you can learn as you go!

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

\M

Josef Rebbe's icon

Thank you so much Mattyo! This is a great help for me.

Josef Rebbe's icon

Somehow your patch only works if I switch directions, not if I stop and continue in the same direction.
Can you suggest how to solve that?

Josef Rebbe's icon

After trying out many things I still can't figure out how I can distinguish between one or two number boxes increasing or decreasing.
Is there a switch that switches only if it gets two values as inputs?
Any suggestion is very welcome. I'm learning a lot here.

Many thanks, Josef

benniy's icon

hei josef,

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

as for your later question – maybe this helps:

benniy's icon
Max Patch
Copy patch and select New From Clipboard in Max.

once again (: .. how ever this might very well be doable a bit more clever, but see if it serves your purpose

maroy's icon
Max Patch
Copy patch and select New From Clipboard in Max.

Yet another approach Delay is set to 2500 ms adjust as you like.

benniy's icon

@maroy: i think you accidentally copied mine for your code! would you repost your approach?

maroy's icon

@Benniy I did indeed (sorry), try my original post now.

Josef Rebbe's icon

Thanks a lot Benny and Maroy.

Your patch does the job Maroy.
Only if I connect it to my joystick output (connected via Arduino and Maxuino), which is controlling the two number boxes, it doesn't work because the joystick gives a constant output, and even if the numbers in the number boxes are not changing, they are banged continuously. And that doesn't work with your patch.

Is there a way to make a bangy number box a not bangy one?

Nikolas K's icon

If you place a [change] object before the number boxes, it will only output if the values change.
What do you mean by "bangy" number box?

Josef Rebbe's icon

Awesome Nikolas! Thank you.
With a bangy number box I mean a number box that constantly sends out bangs even when the number isn't changing.
The [change] object works.