LEGO Mindstorms Class: Lesson 1
Some Important LEGO Mindstorm Parts
The NXT-G Programming Environment
Write a simple program to make the brick play a sound
The 'Play Sound' Program The Sound Block Settings
Change the "Play Sound" program to repeat itself 3 times using a loop
The Sound block inside a Loop The Loop Block settings
Building a Door Alarm:
The parts you'll need:
Step 1: Attach connectors to the arms:
Step 2: Attach the arms together, and connect them to the ultrasonic sensor and the brick:
Step 3: Connect a wire from the ultrasonic sensor to port 4 on the brick.
The Door Alarm Program:
Write the Program:
The Loop Block The Loop Block Settings
A Wait Block inside the Loop Block
The Wait block Settings
3. Add a loop after the Wait block, and set the control to "Count" and the "Count" to "3".
A loop inside the main loop The inner Loop settings
4. Put a sound block inside the inner loop and choose a sound to play when the alarm triggers
The finished Door Alarm program
5. Save the program with the name "Door Alarm". Download and test your program. Did it work? Check with your instructors if you have any problems.
If you finish the door alarm try this!
(1) Pretty Tricky: Can you change the program so that the alarm makes a different sound if the object it detects is closer than 6 inches? Hint: You will have to use a "Switch" block to perform different actions if the object is closer than 6 inches, or further than 6 inches. Think carefully about where to put the Switch block, and if some of the existing program needs to go inside the Switch block.
(2) Even Trickier: Can you change the program so that the screen on the brick displays the distance detected? This will require a block that will convert the distance (a number) to text (letters) to be displayed on the screen and a block to display the text. It also requires the use of data wires to carry the output data from the ultrasonic sensor to the converter block, and from the converter block to the display block. Don't worry if you can't do this one yet, we'll be covering data wires later in the class.
(see your instructors for help with the answers)