/////////////////////////////////////////////////////////////////////////////// // // Original System: LEGO Robotics Sample Code // Subsystem: Bluetooth Commander // Workfile: Bluetooth.nxc // Revision: 1.0 - 17 December, 2008 // Author: J. Marvel // // Description // =========== // Sample code for reading messages from a host computer via a Bluetooth link. // This code assumes that the PC is the master of the connection. /////////////////////////////////////////////////////////////////////////////// #define INBOX 0 #define OUTBOX 1 string in, feed; int cmd; //! @brief Interpret the Bluetooth commands being sent by the user application //! sub BTHandler() { ReceiveRemoteString(INBOX, true, in); if (StrLen(in) > 0) { cmd = StrToNum(in); switch(cmd) { case 0: feed = "Run "; break; case 1: feed = "CMD1"; break; case 2: feed = "CMD2"; break; case 3: feed = "CMD3"; break; case 4: feed = "CMD4"; break; default: cmd = -1; feed = "Unknown"; break; } if (cmd >= 0) { PlayToneEx(262, 400, 5, FALSE); } TextOut(10, LCD_LINE2, feed, false); } } //! @brief The main program loop //! task main() { int n; int c = 0; TextOut(10, LCD_LINE1, "BT:Rcvr", true); while (true) { //! Get input from the PC BTHandler(); { //! To do: write command handling code here } cmd = -1; } }