Generator signal for servos and esc's

Dependencies:   mbed

Revision:
0:96da12aef31f
--- /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