Sorry, das wird wirklich nicht mitgeliefert ...
Example_Hallo_01.c :
Code:
/*
* ****************************************************************************
* RP6 ROBOT SYSTEM - ROBOT BASE EXAMPLES
* ****************************************************************************
* Example: Ask for user's name
* Author(s): Dirk
* ****************************************************************************
* Description:
* This sample program shows how to use the RP6Library functions to receive
* data with the serial interface. It asks for the user's name.
*
* ############################################################################
* The Robot does NOT move in this example! You can simply put it on a table
* next to your PC and you should connect it to the PC via the USB Interface!
* ############################################################################
* ****************************************************************************
*/
/*****************************************************************************/
// Includes:
#include "RP6RobotBaseLib.h" // The RP6 Robot Base Library.
// Always needs to be included!
/*****************************************************************************/
// Ask for the user's name
/**
* Here we ask for the user's name and receive the answer from the user.
* The function uses some of the reception routines of the RP6Library.
* It is called from the main loop (s. below).
*/
void askAQuestion(void)
{
uint8_t charsToReceive;
writeString_P("Wie heisst du? (max. 32 Zeichen)\n");
charsToReceive = 32; // we want to receive maximum 32 characters
// ------------------------------------------
// Receive Answer (UPDATED - this was changed for compatibility with new RP6Lib):
char receiveBuffer[charsToReceive+1]; // our reception buffer is one byte larger
// than the data we want to receive, because
// we also need to receive the "Newline" character!
clearReceptionBuffer(); // Make sure reception Buffer is empty and no junk data
// is left in it.
uint8_t buffer_pos = 0;
while(true) // Loop until we received one line of Data!
{
if(getBufferLength()) // Check if we still have data (means getBufferLength()
{ // is not zero)
receiveBuffer[buffer_pos] = readChar(); // get next character from reception buffer
if(receiveBuffer[buffer_pos]=='\n') // End of line detected!
{
receiveBuffer[buffer_pos]='\0'; // Terminate String with a 0, so other routines.
buffer_pos = 0; // can determine where it ends!
// We also overwrite the Newline character here.
break; // We are done and can leave reception loop!
}
else if(buffer_pos >= charsToReceive) // IMPORTANT: We can not receive more
{ // characters than "charsToReceive" because
// our buffer wouldn't be large enough!
receiveBuffer[charsToReceive]='\0'; // So if we receive more characters, we just
// stop reception and terminate the String.
writeString_P("\n\nDu hast mehr Zeichen als erlaubt eingegeben!\n");
break; // We are done and can leave reception loop!
}
buffer_pos++;
}
}
writeChar('\n');
// ------------------------------------------
// Do something with the received answer:
// Question: What's your name?
writeString_P("Hallo \"");
writeString(receiveBuffer); // Output the user's name as a String
writeString_P("\" !\n");
}
/*****************************************************************************/
// Main function - The program starts here:
int main(void)
{
initRobotBase(); // Always call this first! The Processor will not work
// correctly otherwise.
setLEDs(0b111111); // Turn all LEDs on
mSleep(500); // delay 500ms
setLEDs(0b000000); // All LEDs off
// Write a message to UART:
writeString_P("\nHallo! Mein Name ist RP6!\n\n");
askAQuestion(); // Ask for the name and write it to UART
writeString_P("\nDas war's! Hier ist das Programm zuende!\n\n");
while(true) {
}; // Here we rest in peace!
// ---------------------------------------
return 0;
}
/*****************************************************************************/
// EOF
Gruß Dirk
Lesezeichen