Equipment
- Lego® MindstormsTM SDK
- Lego RCXTM Microcomputer
- Infrared Transmitter (Serial or USB)
- Three LEDs (optional, since LCD display can also be used to tell the user the sequence of input signals required of the user)
- Three Touch Input Sensors
Use Lego’s LASM assembly language to write a program that can play a game of Simon Says on the yellow RCX brick. The brick will tell the user a pattern of input signals (using tones and lights) and then expect the user to repeat that pattern via three touch sensors (or light sensors) correctly in order for the length of the pattern to increase. The pattern’s creation and maintenance during a game will be supported in the program through use of the abstract concept of a queue for the program to “remember” the key sequence and use of the concept of randomness to generate test sequences. In addition to experience with assembly language programming, this project will give you familiarity with the following:
Using the RCX: When you turn on your RCX (press the ON-OFF button), you’ll see four zeros on the RCX's LCD display followed by a stick figure, followed by a 1 (see figure). The four zeros actually are a clock that shows how long the RCX has been turned on. As each minute goes by, the clock will increase by one unit. If you do not see four zeros when you turn the RCX on, that means your batteries either died or temporarily lost contact inside the RCX, causing all firmware in the RCX to be lost. If this happens, you will need to redownload the firmware to the RCX. When you start coding and downloading your program into the RCX, remember that after you get the code into your RCX you need to press the green RUN button to execute the program. You should not need to press the VIEW or PRGM buttons at all. VIEW is used to see what value is being read in by the sensor port, or what direction a motor port is running in. By repeatedly pressing VIEW you can cycle through all sensor and motor ports. If the number after the stick figure ever becomes something other than 1, please press the PRGM button repeatedly until you see a 1. Your RCX may turn itself off after 5 minutes. This is to conserve battery power and is completely normal.
Using the LASM Editor: At the end of this description is a screen shot of the LASM Editor/Assembler, with a sample portion of code displayed in the editor.
The RCX can actually support the interleaved execution of more than one task (process) at a time. You will not need to use more than one task for this project. However, you’ll still need to start the one task you’re writing with the task 0 directive, and you’ll need to end that task’s code with the endt directive.
You should find the text boxes in the screen shot helpful in using the Editor. The buttons not referenced in the screen shot won’t be needed in your project. In the Editor’s top menu there is a HELP menu from which you can look up all LASM commands as well as the meanings of all Editor buttons and settings.
Coding Help Part 1: Write code in the LASM editor to set up your sensor ports so that they can access touch sensors in Boolean mode. For this part’s preliminary version of the final program, define some fixed-length constant sequence of input signals in an array ahead of time and have the program only play that for easier debugging. Implement the Simon Says algorithm taking into account what to do if the user is incorrect. Things to consider: how will the user know which sensor to press? You can display a number or character on the RCX’s LCD, light up LEDs attached to the output ports, play sounds, or perhaps do something else. How will the user know he/she entered the next correct signal in the sequence? Should you play a tone when the user presses an input button? How will the program mark time before deciding that the user is too late in entering a signal (hint: you may need to consider looping over a command that checks what a timer register contains...see the “timer source” documentation on page 6-7 of the Firmware Overview)? Figure out all of these ideas before coding.
When you want to display a value on the LCD in some format, you will often need to use the disp command followed immediately by the view command. The disp only sets up special hidden registers to show what thing you want to display in the way you want to display it; the view command is what you use to actually cause something in a register to be displayed according to the settings set up in the last disp command executed.
Coding Help Part 2: Once the pre-defined sequence works, we must now concentrate on a random sequence. Lego has a built in source number (4) for specifying random values as arguments to machine instructions, so there is not even a need to create a junk variable or call a subroutine of some sort as with other hardware platforms. Remember, however, to take into account that the random numbers are generated in the range from 0 to the bound specified, so it will make your program’s logic more straightforward to represent the input buttons internally as 0,1,2 instead of the 1,2,3 shown on the RCX case. Remember though that on the LCD you’ll need to display 1, 2, 3 if you are using the LCD to tell the user what button to push next in the sequence. Each new random number your program creates will have to be stored into the queue, but this is only if the user can enter the correct sequence. The sequence should begin with one random input number and grow as the user enters data correctly. How will the program know that the sequence has reached a maximum length?
All of the commands listed should be referenced to the manual distributed in printed form or available in the Mindstorms SDK as the .pdf LASM Byte Codes. The following is by no means an exhaustive account of the functions, but is meant to call attention to the most important ones. The exhaustive account is the aforementioned .pdf file.