Code for tone generation over serial connection
Dependencies: RPCInterface mbed
Fork of RPC_Function_Example by
Revision 2:3d9bd88b5b75, committed 2016-11-01
- Comitter:
- natergater
- Date:
- Tue Nov 01 16:16:08 2016 +0000
- Parent:
- 1:50a40baa79bf
- Commit message:
- 4180 mbed project
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 50a40baa79bf -r 3d9bd88b5b75 main.cpp --- a/main.cpp Sat Mar 12 02:39:07 2016 +0000 +++ b/main.cpp Tue Nov 01 16:16:08 2016 +0000 @@ -1,44 +1,38 @@ +//Code for mbed C# Piano project +//Based on RPC Example code + #include "mbed.h" #include "mbed_rpc.h" -/** - * This example program has been updated to use the RPC implementation in the new mbed libraries. - * This example demonstrates using RPC over serial - */ -Serial pc(USBTX, USBRX); +Serial pc(USBTX, USBRX);//Replace With Bluetooth + +//define RPC function void moveTo(Arguments *in, Reply *out); RPCFunction rpcMove(&moveTo, "moveTo"); -double xLoc, yLoc; + +//Speaker Control +double pwmVal; +PwmOut PWM(p21); int main() { - //The mbed RPC classes are now wrapped to create an RPC enabled version - see RpcClasses.h so don't add to base class - - // receive commands, and send back the responses + char buf[256], outbuf[256]; while(1) { + //Get Serial Arguments pc.gets(buf, 256); //Call the static call method on the RPC class RPC::call(buf, outbuf); - pc.printf("%s\n", outbuf); + } } // Make sure the method takes in Arguments and Reply objects. void moveTo (Arguments *in, Reply *out) { bool success = true; + pwmVal = in->getArg<float>(); - // In this scenario, when using RPC delimit the two arguments with a space. - xLoc = in->getArg<double>(); - yLoc = in->getArg<double>(); - - // Have code here to move robot to location (xLoc, yLoc) and update success. - + PWM.period(1.0/(pwmVal));//Set speaker Frequency + PWM = 0.5;//Set speaker amplitude char buffer[200]; - sprintf(buffer, "Successfully moved to location (%f, %f)", xLoc, yLoc); - if (success) { - out->putData(buffer); - } else { - out->putData("Failed to move to location."); - } }