How can this expression be simplified?
Two inputs: A & B, one output: X
L && H || L &&L || H && L == L, else ==H
How can this expression be simplified?
Two inputs: A & B, one output: X
L && H || L &&L || H && L == L, else ==H
Do you mean
L ,L gives L
L, H gives L
H, L gives L
but
H, H gives H
?
That looks like a logical AND condition, use the C/C++ operator &&
Show the context where this is used, how you do it exactly depends on what you up to.
Or tell us what you mean if I misinterpreted.
a7
Two detectors A and B, with active status (detection) = low.
So, only if one of the detectors are active (detection) should output be low. Else = high.
Basically an OR gate with inverted inputs and inverted output.
Is there a simplified expression for this expression?
..nand?
A (INV) + B (BINV) = X (INV) ?
..
or..
INV ( INV (A) + INV (B) ) = output ..?
.. But how to express this in an if condition given A and B, with result: INV (A) && INV (B) = LOW
OK, your description was ambiguous and presented in a non standard manner.
A B output
0 0 ____
0 1 ____
1 0 ____
1 1 ____
Fill in the chart above. I have a feeling it isn’t simply a matter of logic, but timing also, let’s see.
And while you are at it, put it in the context of the code you are working with. How this is done is depends on how you are using it, what you want to come out with.
Be way ahead of the back and forth by posting a complete sketch, just so it is tots clear.
a7
A B output
1 1 1
0 1 0
1 0 0
0 0 0
That is AND, use the C/C++ && operator.
if A and B are HIGH, so should be the output. Otherwise the output is LOW.
We are missing… the context that makes you think I haven’t answered your question.
a7
Of course, stupid of me.
ACK, no sweat, not stupid.
Blame it on something else, like no coffee yet or.
a7
If you don't like to mix HIGH(1)/LOW(0) with true(1)/false(0) (which shouldn't be a problem I think), then this is the simplest form:
output = (A == B) ? HIGH : LOW;
That does not do what is required
Oo, you are right, that is XNOR. My bad.
Then bitwise AND.
output = A & B;
It is required that De Morgan be mentioned.
So.
a7
Yeah, that was something. But then you offered the chart in #4, and I hope OP filled that with his real intention.
Can you explain the real world problem that is behind this, that is assuming that there is one and that it not just an academic exercise.
You have said that there are two detectors which are active LOW and you appear to want a combined result from the pair of them.
If this is a circuit with two open collector type sensors you could, incidentally, connect the two outputs together and save an Arduino pin (if it is enough to know that at least one of the devices was triggered but without knowing which one).
You can't, however, connect two push/pull outputs together because they may "fight".
OK, so:
L, H -> L // One (but not both) are LOW -> LOW
H, L -> L // One (but not both) are LOW -> LOW
L, L -> H // Both are LOW -> HIGH
H, H -> H // Both re HIGH -> HIGH
That would be equivalent to:
(A == B) // HIGH if they are the same, LOW if they are different
The truth table given by OP in #5 is different. So this is a mystery at this point.
Truth seems to be an obsolescent concept, how far behind can truth tables be?
a7
x = A && B;
Hi 6v6gt, this is for a practical issue (and with academic intentions ).
Two sensors, "a" (named "A" in my initial post) and "1" (named "B" my initial post) are used to command a relay.
An active sensor = L, when nothing gets detected then sensor output = H.
If either a or 1 is H or L then output = L
If both are H then output = H
The A and B in my initial post are for sensors "a" and "1" in whose states and outputs I am interested for this thread.
Currently I use an if statement
if (A==H && B==L || A==L && B==H || A==L && B==L) {};
I would like to have above condition simplified, so that definitely a L gets sent to the output; however, this L refers to an action taken only if the above statement = true (H).
If both sensors are inactive (both H) then no action is allowed.
Following alto777 (#6) then indeed AND, however the if condition I use should not take action if A && B = true.
So I think my truth table (#5) was wrong and should have been this:
A B output
1 1 0
0 1 1
1 0 1
0 0 1
This whole mess should be one sentence then? You have two active low sensors and want to take action if either or both of them are activated (become LOW)?
The new truth table is a simple NAND.
output = !(A && B) ? HIGH : LOW;
(I'm gonna ignore what you wrote a few lines before the new truth table)
If either a or 1 is H or L then output = L
If both are H then output = H