![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
demo code for mbed iterface
Dependencies: RPCInterface mbed
Fork of RPC_RangeFinderDemo by
main.cpp@0:5e8f67a3fc53, 2010-09-20 (annotated)
- Committer:
- MichaelW
- Date:
- Mon Sep 20 14:39:23 2010 +0000
- Revision:
- 0:5e8f67a3fc53
- Child:
- 1:e5e4988258b9
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MichaelW | 0:5e8f67a3fc53 | 1 | #include "mbed.h" |
MichaelW | 0:5e8f67a3fc53 | 2 | #include "SerialRPCInterface.h" |
MichaelW | 0:5e8f67a3fc53 | 3 | #include "SRF08.h" |
MichaelW | 0:5e8f67a3fc53 | 4 | |
MichaelW | 0:5e8f67a3fc53 | 5 | using namespace mbed; |
MichaelW | 0:5e8f67a3fc53 | 6 | |
MichaelW | 0:5e8f67a3fc53 | 7 | //Create the interface on the USB Serial Port |
MichaelW | 0:5e8f67a3fc53 | 8 | SerialRPCInterface RPC(USBTX, USBRX); |
MichaelW | 0:5e8f67a3fc53 | 9 | void ReadRange(char * input, char * output); |
MichaelW | 0:5e8f67a3fc53 | 10 | RPCFunction RangeFinder(&ReadRange, "RangeFinder"); |
MichaelW | 0:5e8f67a3fc53 | 11 | SRF08 srf08(p9, p10, 0xE0); // Define SDA, SCL pin and I2C address |
MichaelW | 0:5e8f67a3fc53 | 12 | DigitalOut myled(LED1); |
MichaelW | 0:5e8f67a3fc53 | 13 | |
MichaelW | 0:5e8f67a3fc53 | 14 | int main() { |
MichaelW | 0:5e8f67a3fc53 | 15 | //The range finder demo also uses 2 servos but these will be handled entirly over the RPC |
MichaelW | 0:5e8f67a3fc53 | 16 | |
MichaelW | 0:5e8f67a3fc53 | 17 | while(1) { |
MichaelW | 0:5e8f67a3fc53 | 18 | myled = 1; |
MichaelW | 0:5e8f67a3fc53 | 19 | wait(0.2); |
MichaelW | 0:5e8f67a3fc53 | 20 | myled = 0; |
MichaelW | 0:5e8f67a3fc53 | 21 | wait(0.2); |
MichaelW | 0:5e8f67a3fc53 | 22 | } |
MichaelW | 0:5e8f67a3fc53 | 23 | } |
MichaelW | 0:5e8f67a3fc53 | 24 | |
MichaelW | 0:5e8f67a3fc53 | 25 | //As neither I2C nor the SRF08 library is avalible directly over RPC we create a Custom Function which we make RPCable by attaching to an RPCFunction |
MichaelW | 0:5e8f67a3fc53 | 26 | void ReadRange(char * input, char * output){ |
MichaelW | 0:5e8f67a3fc53 | 27 | //Format the output of the srf08 into the output string |
MichaelW | 0:5e8f67a3fc53 | 28 | sprintf(output, "%f", srf08.read()); |
MichaelW | 0:5e8f67a3fc53 | 29 | } |