.comment-link {margin-left:.6em;}

December 29, 2006

 

NXT Tip of the Day #3 - Using the Touch Sensor

Today you decide you want to do different things depending on whether the touch sensor is pressed or not. The touch sensor is a button, and your NXT-G program can make decisions depending on which state it is in.

To do this, you would use a Switch Block. By default, it is set up to make a decision using the touch sensor, but it has many other uses.

When you add a Switch Block, a box shows up in your program with the "switch"part on the left. Inside the box are two sequence beams, instead of the usual one. The blocks (you have to add them, of course) on the top beams are only run if the switch condition is "true". The bottom is run for "false".

The condition is indicated by the choices in the panel at bottom-left. Check that the Port is the one you have wired the sensor to, and change it if necessary. Everything else should be already set correctly for this use.

In the example to the right, you are running a car with motors connected to ports B and C. If the touch sensor is pressed when it gets to this part of the program, it will run forward for 2 seconds. If not, it will go backwards for 2 seconds. If this was the complete program, you would have to press the button as the program is started to have the car go forward.

Comments:
Thanks A LOT! This really helps me to understand some things that i couldn't find on the internet.
Thank you. ^.^
 
Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?