Page 205 - The Unofficial Guide to Lego Mindstorms Robots
P. 205

194


          NQC, but the syntax and usage is slightly different. In this  section,  I'll describe the important  functions of legOS and
          d emonstrate how they are used.

          T here are, of course, different levels at which you can use legOS. I'll describe the "user-level" functions, meaning the functions
          you can call without knowing much abo ut what's inside legOS. If  you're looking for even more power, the full source code of
          le gOS is freely available; you can read it, debug it, or reprogram it as much as you'd like.∗

          U sing the Display

          le gOS is surprisingly capable when it comes to managing the display on  the RCX. Aside from just disp laying num bers, you
          can ask legOS to approximate a text string using the display, as we did in the HellolegOS.c example.

          N umbers and symbols (rom/lcd.h)

          M ost of the useful display functions are defined in rom/lcd.h. The first function you should learn is lcd_refresh():

          vo id lcd_refresh(void)
          This is the function that makes it all happe n. After you call any other display function, you must call lcd_refresh(): to
          ac tually update the display.

          To display a number, use lcd_number():

          void lcd_number(int i, lcd_number_style n, lcd_comma_style c )
          Us e this function to show a number, i, on the display. The number style is one of sign, unsign or digit. Signed and
          unsi gned numbers are shown in  the main display area, while digitshows a single digit on the right side of the display. The
          comma style is digit_comma  (for use with the digit number style), e0, e_1, e_2 or e_3, indicating the number of
          digits to the right of the decimal point.

          In many cases, you won't need to call lcd_number ()  directly; rom/lcd.h includes definitions for four macros that simplify
          the process of displaying numbers:

          lcd_int(i)
          Use this macro to display a signed integer. Values over 9999 are shown as 9999.

          lcd_unsigned( u)
          This macro displays an unsigned val ue. Leading digits are padded with zero if necessary—for example, 123 is shown 0123.

          ∗ The source  code is subject to the Mozilla Public License (MPL), which is fully described at the following URL:
          http://www.mozilla.org/MPL/ .
   200   201   202   203   204   205   206   207   208   209   210