void cputc(char c, int pos)
Use this method to display a character at the given position. Valid positions are 0 through 4, where 0 is the right-most position (the single digit at the right of the display) and 4 is the left-most
position.
void cputw(unsigned word)
This function displays the supplied value as four hexadecimal digits.
Controlling Outputs (direct-motor.h)
Controlling the outputs with legOS is very easy. All you need to do is give the output a direction and a speed.
void motor_a_dir(MotorDirection dir)
void motor_b_dir(MotorDirection dir)
void motor_c_dir(MotorDirection dir)
These functions set the direction of the RCX's outputs. The dir value can be fwd, rev, brake, and off. The off mode is the same as Float() in NQC.∗
void motor_a_speed(unsigned char speed)
void motor_b_speed(unsigned char speed)
void motor_c_speed(unsigned char speed)
These functions set the speed for the outputs. Of course, the speed only really matters when the output direction is fwd or rev. Values range from 0 to 255. You can use the handy constants
MIN_SPEED and MAX_SPEED if you wish.
To set outputs A and C running forward at top speed, do this:
motor_a_dir(fwd);
motor_c_dir(fwd);
motor_a_speed(MAX_SPEED);
motor_c_speed(MAX_SPEED);
Working with Inputs (direct-sensor.h)
In legOS, support for inputs is rudimentary. Remember all that nice input value processing in NQC and pbFORTH? In legOS, you have to deal with the raw input values, except for light and
rotation sensors. The following macros return the raw value of the inputs:
SENSOR_1
SENSOR_2
SENSOR_3
BATTERY
Use these macros to retrieve the raw value of the corresponding input. BATTERY returns an indication of the battery level. The raw values are in the range from 0x0000 to 0xffff.
Don't expect sensors to use the full range of raw input values. You might think a touch sensor would produce a value of 0x0000 when it's pressed and 0xffff when it's not pressed, but the actual
values are not as extreme. The rule of thumb for testing touch sensors is to test if the value falls below 0xF000, like this:
∗ If you're accustomed to working with NQC, don't get confused here:
off
in legOS is the same as
Float()
in NQC, while
brake
in legOS is the same as
Off()
in NQC.
Page 196
Need help?
Do you have a question about the MINDSTORMS Robots and is the answer not in the manual?