LEGO MINDSTORMS Robots Manual page 179

Unofficial guide
Table of Contents

Advertisement

The rotation sensor code does not work in the March 30, 1999 build of legOS 0.1.7.
Using the Buttons (direct-button.h)
legOS provides one function and some other handy definitions to describe the state of the front panel buttons:
int button_state(void)
This function returns a value that indicates the state of the RCX's four buttons. Use the following macros to interpret the returned value.
PRESSED(state, button)
RELEASED(state, button)
These macros return a boolean value indicating if the specified button was pressed or not. To use these macros, pass the result of button_state() as the state parameter and the name
of a button for button. Buttons names are BUTTON_ONOFF, BUTTON_RUN, BUTTON_VIEW, and BUTTON_PROGRAM.
For example, the following code tests the state of the View button:
if (PRESSED(button_state(), BUTTON_VIEW)) {
// View button is pressed.
}
To test the state of more than one button, it makes sense to store the result of button_state(), like this:
int state;
state = button_state();
if (PRESSED (state, BUTTON_VIEW)) {
// View button is pressed.
}
if (PRESSED(state, BUTTON_PROGRAM) ) {
// Program button is pressed.
}
The Infrared Port (direct-ir.h)
To send data out the IR port, just use the dir_write() function:
size_t dir_write(void∗ const buf, size_t len)
This function writes len bytes of data from the supplied buffer out the IR port. It returns the number of bytes written or -1 if there is an error.
Page 198

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

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

Questions and answers

Subscribe to Our Youtube Channel

Table of Contents