### Email question from a student Part 2

Okay, here's one method for determining if the sensors are returning all True values or all False value or a mixture of values.... This means in my previous post that we're talking about a condition of (1 - 1 - 1) to get the Switch block to execute a True path - any other combination will have the Switch block execute the False path.

One of the easiest ways to do this is to use a Logic block configured to do an AND operation. Read over the Logic block's help files to learn about the other options (OR, XOR, NOT), but for now all you need to know is that the Logic block will take two logic values (one in data plug A and one in data plug B). The AND operation simply looks at the two values and returns a logic value of its own (coming out of the last data plug, called Result). If both values (A and B) are True, then the Result is True. If both values (A and B) are False then the Result is False. If one or the other (A or B) is False, then Result is False. So, the only way you'll get a Result value of True from a Logic block is if both A and B data plugs have a True value coming in.

Next, we take that Result from the first Logic block and run it a second Logic block (data plug B in my picture) configured to do an AND operation. I take the final sensor's logic value (the Touch sensor in my picture) and connect that sensor's Yes/No data plug to data plug B on the second Logic block. I then run a wire out of the second Logic block's Result data plug into a Switch block's data plug.

See if you can figure out what happens now that you understand that both Logic blocks are performing AND operations on the A and B values sent to them. By using just two Logic blocks, you can check to see if all 3 sensors are reporting True or all 3 are reporting False. All it takes is one sensor to report a False and the Switch block will receive a False signal. Follow along and test this little bit of programming and you'll figure it out.

Jim

Anonymous said…
Sorry Jim, only half true. The final output of the logic you have depicted detects 1-1-1 OR any one of the other 7 combinations, NOT just 0-0-0. You got very close to realising that in your final paragraph but didn't quite make the leap of logic.(Sorry, bad pun)

If our young friend only needs to detect one of the logic combinations then using the logic blocks is the way to go. The original solution requires a lot of code duplication. Unfortunately it would take a good deal of space to display the logic set needed for each outcome so I'll leave that to you if you are interested.
AlexD said…
Well, detecting e.g. 0-0-1 is the same as (not 1) and (not 1) and 1, which would work identically to all one-s after the corresponding not-s are taken.

Alex
I'm not sure I'm following you, Noel... maybe I did make a mistake, but the last Switch block can only be true IF the first Logic block sends a 1 paired with the last sensor's 1... so that makes 1 - 1 - 1. Any other pair will send the program to the False path on the Switch block... or am I not understanding your comment?

I think I did make a mistake in my text stating that the program would detect all True or all False when I should have just said True or False.

Jim
I'm editing the original post to correct my mistake... thanks for pointing it out. Easy enough...

Jim