Output PWM on any pin. Partly based on SoftPWM with some improvements

Revision:
0:813ee8141cdd
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SoftPwmOut.h	Thu Sep 03 08:15:34 2015 +0000
@@ -0,0 +1,45 @@
+#ifndef SoftPWM_H
+#define SoftPWM_H
+#define POSITIVE true
+#define NEGATIVE false
+
+#include "mbed.h"
+
+class SoftPwmOut  
+{
+public:
+    SoftPwmOut(PinName); 
+//    void attach_us(int);
+    void start();
+    void write(float);
+    float read();
+    void pulsewidth(float);
+    void pulsewidth_ms(int);
+    void pulsewidth_us(int);
+    void period(float);
+    void period_ms(int);
+    void period_us(int);
+    void stop();
+    operator float()  { 
+        if ( _width <= 0.0 ) return 0.0;
+        if ( _width > 1.0 )  return 1.0;
+        return _width / _interval;
+    }
+    SoftPwmOut& operator=(float duty)  {
+        _width = _interval * duty;
+        if ( duty <= 0.0 ) _width =  0.0;
+        if ( duty > 1.0 )  _width =  _interval;
+        return *this;
+    }
+    
+private:
+    Timeout _timeout;
+    Ticker _ticker;
+    void TickerInterrupt();
+    void end();
+    DigitalOut _outPin;
+    float _width;
+    float _interval;
+                
+};
+#endif
\ No newline at end of file