Test program for my PPM library.
Connect the PPM input to pin 5 of your mbed, the result of each channel will be printed over serial at 115200.
My channel mapping, yours will be different
- Channel 1 is roll. min 1000. max 1900
- Channel 2 is pitch. min 1000. max 1900
- Channel 3 is throttle < 900 when not connected. min 1000. max 1900
- Channel 4 is yaw. min 1000. max 1900
- Channel 5 is arm. armed > 1800 else unarmed
- Channel 6 is mode. rate > 1800. stab < 1100. else error
- Channel 7 is spare
- Channel 8 is spare
Revision 0:20458b362896, committed 2014-08-26
- Comitter:
- joe4465
- Date:
- Tue Aug 26 15:58:19 2014 +0000
- Commit message:
- Test program for my PPM library.
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PPM.lib Tue Aug 26 15:58:19 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/joe4465/code/PPM/#083ed8cea5ff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Aug 26 15:58:19 2014 +0000 @@ -0,0 +1,46 @@ +#include "mbed.h" +#include "PPM.h" + +//My channel mapping, yours will be different +//Channel 1 is roll. min 1000. max 1900 +//Channel 2 is pitch. min 1000. max 1900 +//Channel 3 is throttle < 900 when not connected. min 1000. max 1900 +//Channel 4 is yaw. min 1000. max 1900 +//Channel 5 is arm. armed > 1800 else unarmed +//Channel 6 is mode. rate > 1800. stab < 1100. else error +//Channel 7 is spare +//Channel 8 is spare + +//PPM object +PPM *_ppm; +//InterruptIn pin (p5) +InterruptIn *_interruptPin = new InterruptIn(p5); +//Connection to the PC +Serial pc(USBTX, USBRX); + +int main() +{ + //Create instance of PPM class + //Pass in interrupt pin, minimum output value, maximum output value, minimum pulse time from transmitter, maximum pulse time from transmitter, number of channels, throttle channel (used for failsafe) + _ppm = new PPM(_interruptPin, 0, 1, 1000, 1900, 8, 3); + + //Setup serial connection + pc.baud(115200); + + //Loop, printing data + while(true) + { + //Array to hold RC commands + float rcCommands[8] = {0,0,0,0,0,0,0,0}; + + //Get channel data (mapped to between 0 and 1 as I passed these in as my max and min in the PPM constructor) + //The throttle channel will return -1 if the signal from the transmitter is lost (the throttle pulse time goes below the minimum pulse time passed into the PPM constructor) + _ppm->GetChannelData(rcCommands); + + //Print + printf("%f, %f, %f, %f, %f, %f, %f, %f\r\n", rcCommands[0], rcCommands[1], rcCommands[2], rcCommands[3], rcCommands[4], rcCommands[5], rcCommands[6], rcCommands[7]); + + //Wait 1 so the data can be read + wait(1); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Aug 26 15:58:19 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/9327015d4013 \ No newline at end of file