Marcelo Costanzo Miranda
/
PPM_SIGNAL_GENERATOR
Generator signal for servos and esc's
Revision 0:96da12aef31f, committed 2020-11-27
- Comitter:
- Marcelocostanzo
- Date:
- Fri Nov 27 14:12:47 2020 +0000
- Commit message:
- V1 FUNCIONANDO
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 96da12aef31f main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Nov 27 14:12:47 2020 +0000 @@ -0,0 +1,38 @@ +#include "mbed.h" + +PwmOut myservo(D6); +AnalogIn pot(A0); +Serial pc(USBTX, USBRX); // tx, rx + +float Map (float inVal, float inMin, float inMax, float outMin, float outMax); + +float i=0.0f, x=0.0f; + +int main() { + + myservo.period(0.02f); + + //Required ESC Calibration/Arming sequence + + //sends longest and shortest PWM pulse to learn and arm at power on + myservo = 0.1; + wait(2.5); + myservo = 0.05; + wait(2.5); + myservo = 0.075; + wait(2.5); + + + while(1){ + x = pot.read(); + i = Map(x, 0.0, 1.0, 0.05, 0.1); + myservo.write(i); + pc.printf("control %f\n\r",i); + wait(0.2); + } +} + +float Map (float inVal, float inMin, float inMax, float outMin, float outMax) +{ + return ( (inVal - inMin)*(outMax - outMin)/(inMax - inMin) + outMin ); +} \ No newline at end of file
diff -r 000000000000 -r 96da12aef31f mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Nov 27 14:12:47 2020 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/5aab5a7997ee \ No newline at end of file