kazushiro tanimoto
/
sagawa_lpc1114
Sagawa Electronics,inc.
Fork of sagawa_lpc1114 by
Diff: SoftPWM/SoftPWM.h
- Revision:
- 0:d90f3421aaef
diff -r 000000000000 -r d90f3421aaef SoftPWM/SoftPWM.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SoftPWM/SoftPWM.h Sat Nov 26 18:33:38 2016 +0000 @@ -0,0 +1,45 @@ +#ifndef SoftPWM_H +#define SoftPWM_H +#define POSITIVE true +#define NEGATIVE false + +#include "mbed.h" + +class SoftPWM +{ +private: + Timeout _timeout; + Ticker _ticker; + void end(); + DigitalOut pulse; + bool positive; + void TickerInterrapt(); + float width; + float interval; +public: + SoftPWM(PinName,bool mode=true); +// 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; + } + SoftPWM& operator=(float duty) { + width = interval * duty; + if ( duty <= 0.0 ) width = 0.0; + if ( duty > 1.0 ) width = interval; + return *this; + } + +}; +#endif \ No newline at end of file