Page 1 of 1
Logic opposite?
Posted: 17 Jul 2012, 17:16
by legostormrobot
Ok, I'm now wondering how to make something that could be called an opposite block. So say I have an rotation sensor reading going into a variable. If that variable reads forward (I'm assuming yes or 1), how could I wire it to a motor block to make it go reverse (maybe no or 0?)? I'm assuming it would have to do with a logic block...
Re: Logic opposite?
Posted: 17 Jul 2012, 21:36
by hergipotter
I don't use NXT-G but there sure is a "NOT" Block, isn't it?
Re: Logic opposite?
Posted: 17 Jul 2012, 22:48
by mattallen37
You want a 1 to be 0, and a 0 to be 1? How about using x = 1 - n ?
Re: Logic opposite?
Posted: 18 Jul 2012, 09:54
by h-g-t
In this sort of situation I normally use +1 as forward and -1 as reverse.
All you have to do is multiply by -1 to change the sign.
Re: Logic opposite?
Posted: 24 Jul 2012, 23:54
by legostormrobot
There were a couple my blocks on the lego website that when put together make an "opposite" block. So the logic to number converts logic (yes) to number (1) and then number to logic converts odd numbers to false and even numbers to true, so in this example, the input 1 would be made false and the input 0 would be made true.
The "not" block can work with a switch to say if true do this, if false do that.
If I converted logic to number, (l=logic) l -1 should work, then convert it back to logic.... if it counts -1 as true! Might work...