VEX2 Functions Display

From ROBOTC API Guide
Revision as of 18:59, 10 February 2012 by Bfeher (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Main >> CORTEX >> Functions and Variables >> Display


For information about ROBOTC string, please see the article: Strings.


Color Key
Function:
Variable:


Information

ROBOTC has a rich set of functionality for drawing text and shapes on the LCD screen. The NXT is equipped with a 100 wide by 64 pixels high display.
  • The bottom left corner is point (0, 0) and the top right corner of the display is point (99, 63).
  • There are eight text lines numbers 0 to 7. 0 is the top line and 7 is the bottom line of the display.
Specifier Output Example Code Example Output
%d or %i Signed decimal integer "%d" 4246
%e Scientific notation (mantise/exponent) using e character "%e" 3.9265e+2
%E Scientific notation (mantise/exponent) using E character "%E" 3.9265E+2
%f Decimal floating point number "%f" 3.14159
%o Signed octal "%o" 157
%s String of characters "%s" ROBOTC
%x Unsigned hexadecimal integer "%x" 7fa
%X Unsigned hexadecimal integer (capital letters) "%X" 7FA
%c Character "%c" b


NOTE on Displaying Digits: When displaying floats, for example, you can tell ROBOTC how many decimals places to display. This is standard across all 'C' - like programing languages. For example, if your float is PI (3.14159265), but you only want to dispay "3.14", your string should contain, "%1.2f".

The number before the decimal is how many digits before the decimal you wish to display, while the number after the decimal is how many digits after the decimal you wish to display. So "%1.2f" tells us to display one digit before the decimal and two digits after the decimal, with "3.14" as the final result.


The tag can also contain flags, width, .precision and modifiers sub-specifiers, which are optional and follow these specifications:

Specifier Description Example Output
%d Prints a decimial integer 50
%6d Prints a decimal integer, at least 6 characters wide _ _ _ _ 50
%f Prints a floating point number 50.5
%6f Prints a floating point number, at least 6 characters wide _ _ _ 50.5
%.2f Prints a floating point number, with at least 2 decimal places 50.50
%6.2f Prints a floating point number, with at least 6 characters wide and 2 decimal places __ 50.50

Note: Underscore ( _ ) character denotes a space.


bNxtLCDStatusDisplay

bool bNxtLCDStatusDisplay
(bool) Boolean variable that indicates whether the top status line display on the LCD should be present on user-drawn LCD screens.
bNxtLCDStatusDisplay = true;   // the NXT top status line WILL display on user-drawn LCD screens
bNxtLCDStatusDisplay = false;  // the NXT top status line WILL NOT display on user-drawn LCD screens


eraseDisplay

void eraseDisplay()
(void) Erases the complete NXT LCD display.
eraseDisplay();  // erase the entire NXT LCD display


nxtClearPixel

void nxtClearPixel(const int xPos, const int yPos)
(void) Clears a single pixel on the NXT LCD screen.
Parameter Explanation Data Type
xPos int
yPos int
int X = 50;           // create and initialize variable 'X' = 50  
int Y = 32;           // create and initialize variable 'Y' = 32  
nxtClearPixel(X, Y);  // clear a pixel at position (X, Y)


nxtDisplayBigStringAt

void nxtDisplayBigStringAt(const int xPos, const int yPos, string sFormatString, ...)
(void) Formats a text string and displays it at any (X,Y) coordinate on the LCD display. Drawing uses a large font that is 16-pixels high.
Parameter Explanation Data Type
xPos X-coordinate of pixel to start text from int
yPos Y-coordinate of pixel to start text from int
sFormatString the string(s) to display
(can be formatted!)
string
int printMe = 1;                                              // create and Initialize 'printMe' = 1
int printMeToo = 2;                                           // create and Initialize 'printMeToo' = 2
nxtDisplayBigStringAt(0, 31, "%d, %d", printMe, PrintMeToo);  // displays (in large font): "1, 2" 
                                                              // beginning at (0, 31)


nxtDisplayBigTextLine

void nxtDisplayBigTextLine(const int nLineNumber, string sFormatString, ...)
(void) Displays a text string on one of the 8 possible text lines. Drawing uses a large font that is 16-pixels high.
Parameter Explanation Data Type
nLineNumber The line to print a string on
([top] 0 to 7 [bottom])
int
sFormatString the string(s) to display
(can be formatted!)
string
int printMe = 1;                                          // create and Initialize 'printMe' = 1
int printMeToo = 2;                                       // create and Initialize 'printMeToo' = 2
nxtDisplayBigTextLine(3, "%d, %d", printMe, PrintMeToo);  // displays on line 3 (large): "1, 2"


nxtDisplayCenteredBigTextLine

void nxtDisplayCenteredBigTextLine(const int nLineNumber, string sFormatString, ...)
(void) Displays a text string on one of the 8 possible text lines. The text is horiztonally centered on the LCD display. Drawing uses a large font that is 16-pixels high.
Parameter Explanation Data Type
nLineNumber The line to print a string on
([top] 0 to 7 [bottom])
int
sFormatString the string(s) to display
(can be formatted!)
string
int printMe = 1;                                                  // create and Initialize 'printMe' = 1
int printMeToo = 2;                                               // create and Initialize 'printMeToo' = 2
nxtDisplayCenteredBigTextLine(3, "%d, %d", printMe, PrintMeToo);  // displays on line 3 (centered and large): "1, 2"


nxtDisplayCenteredTextLine

void nxtDisplayCenteredTextLine(const int nLineNumber, string sFormatString, ...)
(void) Displays a text string on one of the 8 possible text lines. The text is horiztonally centered on the LCD display.
Parameter Explanation Data Type
nLineNumber The line to print a string on
([top] 0 to 7 [bottom])
int
sFormatString the string(s) to display
(can be formatted!)
string
int printMe = 1;                                               // create and Initialize 'printMe' = 1
int printMeToo = 2;                                            // create and Initialize 'printMeToo' = 2
nxtDisplayCenteredTextLine(3, "%d, %d", printMe, PrintMeToo);  // displays on line 3 (centered): "1, 2"


nxtDisplayClearTextLine

void nxtDisplayClearTextLine(const int nLineNumber)
(void) Erases a line of text. nLineNumber specifies one of the 8 possible text lines.
Parameter Explanation Data Type
nLineNumber The line to print a string on
([top] 0 to 7 [bottom])
int
nxtDisplayClearTextLine(3);  // clears line 3


nxtDisplayRICFile

void nxtDisplayRICFile(const int nleft, const int nBottom, const string sFileName)
(void) Display a RIC (i.e. "ICON" or "Picture") file on the NXT display at the specified coordinates.
Parameter Explanation Data Type
nLeft int
nRight int
sFileName string
while(true)                                 // infinite loop:
{
  nxtDisplayRICFile(0, 0, "faceclosed.ric");  // display the .ric file, "faceclosed.ric" at pos(x,y)
  wait1Msec(50);                              // wait 50 milliseconds (helps refresh rate of LCD screen)
}


nxtDisplayString

void nxtDisplayString(const int nLineNumber, string sFormatString, ...)
(void) Formats a character string according the the format specified in sFormatString using parameters parm1, parm2, and parm3. Display the result on text line nLineNumber. The remainder of the line is not altered; so that if the result string is 8 characters only the first eight characters of the text line are updated. The contents of the remaining characters on the line are not changed.
Parameter Explanation Data Type
nLineNumber The line to print a string on
([top] 0 to 7 [bottom])
int
sFormatString the string(s) to display
(can be formatted!)
string
while(true)                     // infinite loop:
{
  string s1 = "Theory";           // create the string named s1, "Theory"
  nxtDisplayString(3, "%s", s1);  // display the string, 's1' on line 3
  wait1Msec(50);                  // wait 50 milliseconds (helps refresh rate of LCD screen)
}


nxtDisplayStringAt

void nxtDisplayStringAt(const int xPos, const int yPos, string sFormatString, ...)
(void) Displays a text string at (X,Y) coordinate on the LCD display.
Parameter Explanation Data Type
xPos X-coordinate of pixel to start text from int
yPos Y-coordinate of pixel to start text from int
sFormatString the string(s) to display
(can be formatted!)
string
while(true)                          // infinite loop:
{
  nxtDisplayStringAt(0, 0, "Theory");  // display the string, "Theory" at position (x, y)
  wait1Msec(50);                       // wait 50 milliseconds (helps refresh rate of LCD screen)
}


nxtDisplayTextLine

void nxtDisplayTextLine(const int nLineNumber, string sFormatString, ...)
(void) Formats a text string and displays it on one of the 8 possible text lines. The remainder of the line is padded with blanks.
Parameter Explanation Data Type
nLineNumber The line to print a string on
([top] 0 to 7 [bottom])
int
sFormatString the string(s) to display
(can be formatted!)
string
while(true)                       // infinite loop:
{
  string s1 = "Theory";             // create the string named s1, "Theory"
  nxtDisplayTextLine(3, "%s", s1);  // display the string, 's1' on line 3
  wait1Msec(50);                    // wait 50 milliseconds (helps refresh rate of LCD screen)
}


nxtDrawCircle

void nxtDrawCircle(const int Left, const int Top, const int Diameter)
(void) Draws outline of the circle with the specified coordinates. Note that the point (Left, Top) is where the upper-left corner of a square with side length equal to "Diameter" would be if it were positioned exactly on top of our circle.

DrawCircle 2.jpg

Parameter Explanation Data Type
Left The x-coordinate of the upper left corner of the square with side length equal to diameter of circle int
Top The y-coordinate of the upper left corner of the square with side length equal to diameter of circle int
Diameter The diameter of the circle int
nxtDrawCircle(20, 50, 25);  // display a circle; left border at 20, top border at 50, diameter of 25


nxtDrawEllipse

void nxtDrawEllipse(const int Left, const int Top, const int Right, const int Bottom)
(void) Draws outline of the ellipse with the specified coordinates.
Parameter Explanation Data Type
Left The left-most point of the ellipse int
Top The top-most point of the ellipse int
Right The right-most point of the ellipse int
Bottom The bottom-most point of the ellipse int
nxtDrawEllipse(20, 50, 60, 25);  // display an ellipse; left border at 20, top border at 50, 
                                 // right border at 60, bottom border at 25


nxtDrawLine

void nxtDrawLine(const int xPos, const int yPos, const int xPosTo, const int yPosTo)
(void) Draws a line between two points.
Parameter Explanation Data Type
xPos The X-coordinate of the first point int
yPos The Y-coordinate of the first point int
xPosTo The X-coordinate of the second point int
yPosTo The Y-coordinate of the second point int
nxtDrawLine(20, 50, 60, 25);  // display a line between the points (20,50) and (60,25)


nxtDrawRect

void nxtDrawRect(const int Left, const int Top, const int Right, const int Bottom)
(void) Draws outline of the rectangle with the specified coordinates.
Parameter Explanation Data Type
Left The left-most point of the rectangle int
Top The top-most point of the rectangle int
Right The right-most point of the rectangle int
Bottom The bottom-most point of the rectangle int
nxtDrawRect(20, 50, 60, 25);  // display a rectangle; left border at 20, top border at 50, 
                              // right border at 60, bottom border at 25


nxtEraseEllipse

void nxtEraseEllipse(const int Left, const int Top, const int Right, const int Bottom)
(void) Erases (i.e. clears all pixels) the ellipse with the specified coordinates.
Parameter Explanation Data Type
Left The left-most point of the ellipse int
Top The top-most point of the ellipse int
Right The right-most point of the ellipse int
Bottom The bottom-most point of the ellipse int
nxtEraseEllipse(20, 50, 60, 25);  // erases an ellipse; left border at 20, top border at 50, 
                                  // right border at 60, bottom border at 25


nxtEraseLine

void nxtEraseLine(const int xPos, const int yPos, const int xPosTo, const int yPosTo)
(void) Erases (i.e. clears) the pixels for the line between the specified pair of points.
Parameter Explanation Data Type
xPos The X-coordinate of the first point int
yPos The Y-coordinate of the first point int
xPosTo The X-coordinate of the second point int
yPosTo The Y-coordinate of the second point int
nxtEraseLine(20, 50, 60, 25);  // erase a line between the points (20,50) and (60,25)


nxtEraseRect

void nxtEraseRect(const int Left, const int Top, const int Right, const int Bottom)
(void) Erases (i.e. clears all pixels) the rectangle with the specified coordinates.
Parameter Explanation Data Type
Left The left-most point of the rectangle int
Top The top-most point of the rectangle int
Right The right-most point of the rectangle int
Bottom The bottom-most point of the rectangle int
nxtEraseRect(20, 50, 60, 25);  // erase a rectangle; left border at 20, top border at 50, 
                               // right border at 60, bottom border at 25


nxtFillEllipse

void nxtFillEllipse(const int Left, const int Top, const int Right, const int Bottom)
(void) Fills (i.e. all pixels black) the ellipse with the specified coordinates.
Parameter Explanation Data Type
Left The left-most point of the ellipse int
Top The top-most point of the ellipse int
Right The right-most point of the ellipse int
Bottom The bottom-most point of the ellipse int
nxtFillEllipse(20, 50, 60, 25);  // display a solid ellipse; left border at 20, top border at 50, 
                                 // right border at 60, bottom border at 25


nxtFillRect

void nxtFillRect(const int Left, const int Top, const int Right, const int Bottom)
(void) Fills (i.e. all pixels black) the rectangle with the specified coordinates.
Parameter Explanation Data Type
Left The left-most point of the rectangle int
Top The top-most point of the rectangle int
Right The right-most point of the rectangle int
Bottom The bottom-most point of the rectangle int
nxtFillRect(20, 50, 60, 25);  // display a solid rectangle; left border at 20, top border at 50, 
                              // right border at 60, bottom border at 25


nxtInvertLine

void nxtInvertLine(const int xPos, const int yPos, const int xPosTo, const int yPosTo)
(void) Inverts the pixels for the given line. This function is very useful for functions like drawing a "clock face", a "compass" or a gauge on the LCD screen when you want to "erase" the previous dial pointer and redraw it at a new position. If you use "invert line" for the original drawing and for the "erase" drawing the two calls will cancel each other out! And it work well if the line overdraws some existing pixels -- e.g. some text on the LCD.
Parameter Explanation Data Type
xPos The X-coordinate of the first point int
yPos The Y-coordinate of the first point int
xPosTo The X-coordinate of the second point int
yPosTo The Y-coordinate of the second point int
nxtInvertLine(20, 50, 60, 25);  // invert the pixels on the line from (20,50) to (60,25)


nxtScrollText

void nxtScrollText(string sFormatString, ...)
(void) Shift the LCD image up one line. Thenit formats a text string and displays it on the bottom line of the LCD text screen.
Parameter Explanation Data Type
sFormatString the string(s) to display
(can be formatted!)
int
for(i=0; i<1000; ++i)             // for Loop from 0 to 999 incrimenting 'i' by 1 each time:
{
  nxtScrollText("Scroll #%d.", i);  // display "Scroll #i." (%d is replaced with variable 'i' at runtime)
  wait1Msec(250);                   // wait 520 milliseconds between each iteration of the For Loop
}


nxtSetPixel

void nxtSetPixel(const int xPos, const int yPos)
(void) Sets a single pixel on the NXT LCD screen.
Parameter Explanation Data Type
xPos X-coordinate of pixel int
yPos Y-coordinate of pixel int
nxtSetPixel(42, 46);  // "set" a pixel (make it black) at position (42,46)