NXT-G quick programming guide

The following are examples of programming challenges for LEGO MINDSTORMS NXT Software (NXT-G).

Move Forward, Wait, Move Reverse

move

You will need an NXT car with two motors. Attach one motor to Port A and the other motor to Port C.

  1. Write a program exactly like the one above. Make sure to change both Move blocks to Ports A and C. Set the Duration of each Move block to 2 seconds. The second Move block should have the Direction set to Reverse.
  2. Run the program, and observe the behavior of the NXT car.
  3. Change the amount of time that your car moves forward and backward.
  4. Run the changed program and again, note the behavior of the NXT car. Did the differences in the NXT car’s behavior the second time reflect your changes?

Extra challenge

Draw an NXT brick and label the following parts:

  • Input Ports
  • Output Ports
  • Enter Button
  • Left Button
  • Right Button
  • Back Button
  • USB Port

Wait for Touch

wait_touch

You will need an NXT car with two motors and a touch sensor. Attach one motor to Port A and the other motor to Port C. Attach the touch sensor to Port 1.

  1. Write a program exactly like the one above. Make sure to change the Move block to Ports A and C. Set the Duration of the Move block to 2 seconds. The Wait block should be set to wait for the touch sensor to be pressed.
  2. Run the program, and observe the behavior of the NXT car when you press the touch sensor.
  3. Change the Wait block to wait for the touch sensor to be bumped (pressed and released once).
  4. Run the changed program and again, note the behavior of the NXT car. Did the differences in the NXT car’s behavior the second time reflect your changes?

Extra challenge

Add a second Wait block just after the first Wait block and before the Move block. Set one Wait block to wait until the touch sensor is pressed, and set the second Wait block to wait until the touch sensor is released. When you run this program, how does the NXT car’s behavior compare to the behavior of the car in step 4, above? Compare the efficiency of the code – which do you find easier to make in NXT-G?

Loop

msloop

You will need an NXT car with two motors and a touch sensor. Attach one motor to Port A and the other motor to Port C. Attach the touch sensor to Port 1.

  1. Write a program exactly like the one above. Make sure to change the Move block to Ports A and C. Set the Duration of the Move block to 2 seconds. The Wait block should be set to wait for the touch sensor to be pressed. The loop should continue forever.
  2. Run the program, and observe the behavior of the NXT car when you press the touch sensor.
  3. Press the touch sensor again, and observe the behavior of the NXT car. How many times do you think the car will perform this same behavior when the touch sensor is pressed?
  4. Run the changed program and again, note the behavior of the NXT car. Did the differences in the NXT car’s behavior the second time reflect your changes?

Extra challenge

Make the car continue to drive forward each time the touch sensor is pressed until the touch sensor has been pressed four times in total. Hint: Change the settings of the Loop block. Set the Control to Count, and change the count number.

Change direction with Touch Sensor

direction

You will need an NXT car with two motors and a touch sensor. Attach one motor to Port A and the other motor to Port C. Attach the touch sensor to Port 1.

  1. Write a program exactly like the one above. Make sure to change the Move blocks to Ports A and C. Set the Duration of both Move blocks to Unlimited. The second Move block should have the direction reversed. The Wait blocks should be set to wait for the touch sensor to be pressed. The loop should continue forever.
  2. Run the program, and observe the behavior of the NXT car when you press the touch sensor.
  3. Press the touch sensor again, and observe the behavior of the NXT car. What has changed?
  4. Keep the program running, and continue to press the touch sensor multiple times. You have made the touch sensor into a toggle switch for the direction of the motors of your car!

Extra challenge

Change the direction of each Move block so that at least one Move block causes the car to turn. Now you can control which way the motors turn by pressing a single touch sensor! What are the limitations of this program? What would you like to change about the program?

Light Sensor: Stop a black line

light

You will need an NXT car with two motors, a light sensor, and black electrical tape. Attach one motor to Port A and the other motor to Port C. Attach the light sensor to Port 3.

  1. Write a program exactly like the one above. Make sure to change the Move blocks to Ports A and C. Set the Duration of both Move blocks to 2 seconds. The second Move block should have the direction reversed. The Wait blocks should be set to wait for the touch sensor to be pressed. The loop should continue forever.
  2. Run the program, and observe the behavior of the NXT car when you press the touch sensor.
  3. Press the touch sensor again, and observe the behavior of the NXT car. What has changed?
  4. Keep the program running, and continue to press the touch sensor multiple times. You have made the touch sensor into a toggle switch for the direction of the motors of your car!

Extra challenge

Change the direction of each Move block so that at least one Move block causes the car to turn. Now you can control which way the motors turn by pressing a single touch sensor! What are the limitations of this program? What would you like to change about the program?

Switch

switch

You will need an NXT car with two motors and a touch sensor. Attach one motor to Port A and the other motor to Port C. Attach the touch sensor to Port 1.

  1. Write a program exactly like the one above. Make sure to change the Move blocks to Ports A and C. Set the Duration of all Move blocks to 2 seconds. Notice the directions of the Move blocks – the first is forward, the top block in the switch is all the way to the left, and the bottom block in the switch is all the way to the right. The Switch should be set to be controlled by the touch sensor being pressed.
  2. Add a loop to the program so that it repeats. Hint: put the loop where the program will let you keep using the touch sensor to control the motors. Add a beep so that you know when the cycle begins again.
  3. Run the new program and experiment with steering the NXT car this way. What are the program’s limitations? What would you change about this program?

Extra challenge

Pretend your motor is a generator. Program the generator to turn on when the lights in the room go off, and to turn off when the lighs in the room come back on. The program should be able to perform these tasks repeatedly. Hint: Use one or more loops!

Task split

split

You will need an NXT brick.

  1. Write a program exactly like the one above. Note that the sequence beam has been split into two sections. The Sound block is set to play a sound file – pick any one you like. Make sure the check box next to ‘Wait For Completion’ is checked so that the sound plays until the whole file has finished. Set the Display block to display an image – choose any one you like. Set the Wait block to wait for an amount of time, such as 3 seconds. This Wait block allows the image displayed to continue to be on the screen for some time. Without it, the image would show up so briefly that you probably would not be able to see it!
  2. Run the program and notice how both actions can be performed by the NXT brick at once.
  3. Change the program to perform three tasks at once by adding another arm to the sequence beam. This can be anything you like – you can add a sensor and control it, or add motors and control them, for example.
  4. Run the new program and notice that all three tasks can be performed at once!

Extra challenge

Think about building something other than a car that could do two things at the same time and would need a split task. What would you build and what would it do?

Related posts

Add a comment

You must be logged in to comment.