Une version perso de PwmOut
Une version à peine modifié de la librairie PwmOut
Diff: JMAPwmOut.hpp
- Revision:
- 0:b2ab9e77dd7e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/JMAPwmOut.hpp Fri May 26 14:15:14 2017 +0000 @@ -0,0 +1,45 @@ +#ifndef _JMAPWMOUT_HPP_ +#define _JMAPWMOUT_HPP_ + +#define POSITIVE true +#define NEGATIVE false + +#include "mbed.h" + +class JMAPwmOut { + public : + JMAPwmOut(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 ) return 0.0; + if ( _width > 1 ) return 1.0; + return _width / _interval; + } + JMAPwmOut& operator=(float duty) { + _width = _interval * duty; + if ( duty <= 0 ) _width = 0.0; + if ( duty > 1 ) _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