3 input AND gate

Phil Maguire's icon

Hi all,

I'm trying to make a three-input AND gate and I'm a bit stuck. Below is what I have. I presume I'm missing something very simple?!

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

Roman Thilenius's icon

it is easier to use arithmetics.

up to 8 inputs using expr:

expr ($i1+$i2+$i3+$i4+$i5+$i6+$i7+$i8)==$i9

where the last argument is the number of inputs you want to use.

for 3 you can reduce it to ($i1+$i2+$i3)==3

Phil Maguire's icon

Thanks Roman, but that doesn't work for me. I get a bang whenever I change the first input, regardless of what the other number boxes are set to (even 0).

Roman Thilenius's icon

oh, and otherwise it would be &&, not &!

& is bitwise-and.

Roman Thilenius's icon

a bang? it outputs 1 and 0 (true or not true)

Phil Maguire's icon

Sorry yes that's what I meant. I'm still getting a zero output regardless of the input?

Wetterberg's icon

hey Phil,

does this work for you?

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

Phil Maguire's icon

Thanks! But still getting nothing but zeroes...

Wetterberg's icon

okay, can you briefly describe in plain language the calculation you're trying to do?

is the trouble rooted in using logical operators for this? I see you're using floating numbers...

Phil Maguire's icon

I'm after a three input AND gate that takes floats from 0-1 and outputs a bang (or a 1, whichever), when the three inputs are all above a given threshold (say 0.5).

The scaling in the wider patch is all 0-1 so that would be the most convenient, but if ints work better then I'll go with that.

EDIT - the input for this is a series of fluctuating numbers from a motion sensor. The idea is to have moments where three different values from the sensor trigger a bang when they get above a threshold.

Roman Thilenius's icon

hehe, maybe make a fresh numberbox with no limits set?

Wetterberg's icon

ah, gotcha - yeah, I'd still think we're in the "multiple conditions" side of things.

You can either do three "sensor > threshold" operations and then AND those *afterwards*, or you can do something like this?

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

change object optional, depending on your needs.

Wetterberg's icon

oh, and you can use a big [join 4 @triggers -1] to group up all your floats instead of the pak+tbf

Phil Maguire's icon

hmm, so if I was ANDing them afterwards, I could run them into the example that Roman posted above?

Wetterberg's icon

yeah, basically you'd be doing three separate logical operations, giving you three binary outputs, and you'd just be adding up the zeros and ones and seeing if you get a three.

Wetterberg's icon

oh, should we have been doing [expr $f1 > $f4 && $f2 > $f4 && $f3 > $f4]? I guess.

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


Phil Maguire's icon

Tried it and that works! I think I have what I need now. Thanks everyone :)