PWM_generator

Dependencies:   mbed

Revision:
0:566768f53e4b
Child:
1:1d1a7680a3fe
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Dec 05 05:27:10 2012 +0000
@@ -0,0 +1,25 @@
+#include "mbed.h"
+
+Serial pc(USBTX, USBRX); // tx, rx
+PwmOut esc(p22);
+
+int main() {
+
+    int pulse_buf   =   0;
+    double pulse    =   0;
+    
+    esc.period(0.018);
+    esc.pulsewidth(0.001);
+    
+    while (1) {
+        
+        pulse_buf   =   pc.getc()-48;
+        pulse   =   0.001+0.0001*(double)pulse_buf;
+        if( pulse<0.001 ){  pulse = 0.001;  }
+        if( 0.0019<pulse ){ pulse = 0.0019; }
+        esc.pulsewidth(pulse);
+        pc.printf("%f\r\n", pulse);
+        
+    }
+    
+}