
RP6 ROBOT SYSTEM - 4. Programming the RP6
void writeStringLength(char *data, uint8_t length, uint8_t offset);
Whenever you need to output text with a predefined length and/or offset, you can use
this function.
An example:
writeStringLength("A
BCD
EFG", 3, 1);
Output: “BCD”
writeStringLength("ABCD
EF
G", 2, 4);
Output: “EF”
This function however will occupy RAM for these strings as well and has been designed
for handling dynamic texts. This function is for example used by writeIntegerLength.
void writeInteger(int16_t number, uint8_t base);
This very useful function will output integer values as ASCII Text. From previous
examples we remember, that writeChar(65) outputs 'A' instead of the number 65...
Thus we need a function to output numbers as text strings.
Example:
writeInteger(139, DEC);
Output: “139”
writeInteger(25532, DEC);
Output: “25532”
The function allows you to output the complete range of 16bit signed integers
between -32768 up to 32767. Anyone planning to use numbers beyond these limits
will have to modify the function or alternatively write a special function from scratch!
Now you may wonder why we are using a second parameter “DEC”! The answer is
quite simple: this parameter is controlling the output format for this number. Of
course instead of DECimal (base 10) we may use several alternative output formats,
such as binary (BIN, base 2), octal (OCT, base 8) or hexadecimal (HEX, base 16).
Some examples:
writeInteger(255, DEC);
Output: “255”
writeInteger(255, HEX);
Output: “FF”
writeInteger(255, OCT);
Output: “377”
writeInteger(255, BIN);
Output: “11111111”
These functions are extremely useful for lots of applicatins. Especially to output in-
tegers in HEX or BIN format, as these formats allow you to directly see how the bits
are set in this integer.
- 81 -