Thursday, January 10, 2008

NXT-G Program Basic Lesson 6- Random Block


Use of Random Block







Video Clip Demonstration


As you can see from the images above, the text to display will comefrom the output data plug on the number to TEXT block. The random number generated will stay on the LCD screen until one press the Left Button.

Wednesday, January 2, 2008

NXT-G Program Basic Lesson 5- Switch Block



Lesson on use of Switch Block
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, 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.




Use of Switch Block

The switch block allows one to make choices



The flat view of the swtich block



Tabbed view of the switch block



Five different paths for the switch block





Switch block with two possible paths



Second switch using sound sensor



NXT robot will turn right if the first and second switch block conditions are met





Tuesday, January 1, 2008

NXT-G Program Basic Lesson 4- Loop Block



Lesson on Loop Block
A set of instructions to do over and over and over until
something else happens. It may be that touch sensor
is pressed or the sound sensor detects a noise or the time reaches
infinity.
When dropping a block inside a LOOP block, continue to
hold down the mouse button and move the new block
inside the Loop block until the loop block explains.
A Simple MOVE Block inside a Loop Block



The Control Section of the Loop Block



The Control Section of the Loop Block configured for Time



Loop Block set to forever



A Loop Block configured to break using a touch sensor



Nested Loop
This means a loop inside a loop. When the program runs,
any blocks inside the outer loop block will run. First, the inner loop will run three times
(executing MOVE and SOUND blocks inside it) and then break. Then the Light sensor will send
a True/False Logic response to the outer loop block's data plug. If the Light sensor does not
detect a light level greater than 90, the outer Loop block will not break and will run whatever
is inside it again.



There is a data wire connecting the Light sensor to the outer loop block. In the control section of the outer loop block, the Logic option is selected and wait until it receives a True response from the Light sensor block.
If the Light sensor block does not detect a light level greater than 90, the Yes/No data plug sends a False signal to the outer loop block causing the outer loop block to loop again.