EasyManuals Logo
Home>LEGO>Toy>MINDSTORMS Robots

LEGO MINDSTORMS Robots User Manual

LEGO MINDSTORMS Robots
226 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #128 background imageLoading...
Page #128 background image
BEGIN
BEGIN
1 SENSOR_READ 0=
UNTIL
1 SENSOR_VALUE
showTemperature
isRunButtonPressed
UNTIL
clear
;
To run this program, use the thermometer word. The LCD display will show the temperature read by the sensor until you press the Run button.
The isRunButtonPressed word simply tests to see if Run has been pressed, using the buttonState word. This is how thermometer knows to stop running. showTemperature
takes the top item on the stack and shows it on the display with the decimal point placed to show tenths. The clear word simply erases the entire display using the LCD_CLEAR word.
Page 138
The main program, thermometer, begins by initializing the RCX and the input and button systems. It then configures input 1 for a temperature sensing using the temperature type (2) and the
Celsius mode (A0).
The main part of temperature is a BEGIN UNTIL loop that reads a value from the input and shows it on the display. To retrieve the input value we first have to call SENSOR_READ. This call
is inside its own BEGIN UNTIL loop that waits for SENSOR_READ to return 0, indicating success. Then the actual input value is read using SENSOR_VALUE. A call to showTemperature
puts the input value on the display. Each time through the loop we call isRunButtonPressed; if the button is pressed, we fall out of the loop. A call to clear cleans up the display, and then
thermometer is done.
If you bought LEGO's temperature sensor, you now have yourself a $225 digital thermometer. Chapter 11, Make Your Own Sensors, shows how you can build your own temperature sensor. You
could use that code to make a digital thermometer for only about $202.
Minerva Revisited
To really put pbFORTH through its paces, let's rewrite Minerva's software in pbFORTH. (For a full description of this robot, see Chapter 5, Minerva, a Robot with an Arm.) As with any other
language, the challenge with Forth is to break the large problem into pieces that are small enough to be understood easily. Here's a set of words that will run Minerva. They are defined in bottom-
up fashion, such that the most sophisticated words are at the end.
HEX
: initialize
RCX_INIT
SENSOR_INIT
2 SENSOR_ACTIVE
3 2 SENSOR_TYPE
80 2 SENSOR_MODE
;
: showValue
3002 SWAP 3001 LCD_NUMBER
LCD_REFRESH
;
: sleep
0 0 TIMER_SET
BEGIN DUP 0 TIMER_GET = UNTIL
DROP
;

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the LEGO MINDSTORMS Robots and is the answer not in the manual?

LEGO MINDSTORMS Robots Specifications

General IconGeneral
BrandLEGO
ModelMINDSTORMS Robots
CategoryToy
LanguageEnglish

Related product manuals