For all the code presented here, the include file
  #include "direct-sensor.h"
will need to called out in the source. Here is the layout of the front panel:
The LCD screen and the control buttons are directly accessible to any program. In fact, you must set up a "stop the program" button if you ever expect to gain control of the RCX brick without giving the brick a battery enema.

Here's a sample stopper:


  wakeup_t press_wakeup(wakeup_t data) {
    return PRESSED(button_state(),data);
  }
  
  wakeup_t release_wakeup(wakeup_t data) {
    return RELEASED(button_state(),data);
  }

  int program_stopper(void) {
    /* wait for the button to release */
    wait_event(&release_wakeup,BUTTON_RUN); 
    msleep(250);  /* sleep for 1/4 second, acts as a debounce */
    /* stop this thread until the button is hit */
    wait_event(&press_wakeup,BUTTON_RUN);
    /* kill all the other threads */
    kill(t2...n);
    return 0;
  }

  int main(void) {
    t1=execi(&program_stopper,1,DEFAULT_STACK_SIZE);
    t2...n=some other threads
    tm_start();
    return 0;
  }
The other buttons are read and handled in a thread in the same way.

The buttons are called :

"View" BUTTON_VIEW
"Run" BUTTON_RUN
"Pgm" BUTTON_PROGRAM
"On/Off" BUTTON_ONOFF
The buttons should be checked with the RELEASED and PRESSED macros in direct-button.h. The LCD screen elements can be directly addressed on an element by element basis or by higher level functions. Whenever the LCD screen is written to, lcd_refresh() must be called to write the data to the screen.
lcd_int(int)
will write an signed integer (range -9999 to 9999) to the LCD buffer
lcd_unsigned(int)
same as lcd_int() but unsigned with leading zeros
lcd_clock(int)
write a clock style number (1124 becomes 11.24)
lcd_digit(int)
writes a digit to the right of the little man symbol
lcd_number(int,number_style,comma_style)
lcd_clear(void)
clear the LCD screen
lcd_refresh(void)
writes the buffer to the LCD display, must be called after any of the above operations The individual LCD segments can be controlled as well:
lcd_show(segment)
lcd_hide(segment)
these are the segment names:
     LCD_ARMS LCD_BODY LCD_1LEG LCD_2LEGS
     LCD_n_TOP LCD_n_MID LCD_n_BOT LCD_n_TOPR LCD_n_BOTR LCD_n_TOPL LCD_n_BOTL
               where n=0..4
     LCD_5_MID
     LCD_n_SELECT LCD_n_LEFT LCD_n_RIGHT where n=A..C
     LCD_Sn_SELECT LCD_Sn_ACTIVE where n=1..3 
     LCD_CIRCLE_0 LCD_CIRCLE_1 LCD_CIRCLE_2 LCD_CIRCLE_3
     LCD_DOT_0 LCD_DOT_1 LCD_DOT_2 LCD_DOT_3
     LCD_IR_LOWER LCD_IR_UPPER
     LCD_BATTERY_X

Through the functions prototyped in conio.h it is possible to approximate text printing to the seven segment display. The printed text (of course) looks horrible.
cputw(word)
print a hex word (16 bits)
cputs(string)
print a string
cputc(character,position)
print a character at display position

number_style
digit write to the single digit on the right
sign signed, no leading zeros
unsign unsigned, 0 displayed as 0000
comma_style
digit_comma use only with sign number style
e0 xxxx.
e_1 xxx.x
e_2 xx.xx
e_3 x.xxx
Previous - Motors Main
Monty Stein Dec 18, 1999
CLUG Home