The PWM output by software. Can be output to any pin. It can be used to replace the Pwmout.
Fork of SoftPWM by
Diff: SoftPWM.cpp
- Revision:
- 1:9aba3dc9cd97
- Parent:
- 0:7918ce37626c
--- a/SoftPWM.cpp Wed Oct 23 19:31:14 2013 +0000 +++ b/SoftPWM.cpp Tue Jun 05 12:21:14 2018 +0000 @@ -14,14 +14,14 @@ start(); } -float SoftPWM::read() +double SoftPWM::read() { if ( width <= 0.0 ) return 0.0; if ( width > 1.0 ) return 1.0; return width / interval; } -void SoftPWM::write(float duty) +void SoftPWM::write(double duty) { width = interval * duty; if ( duty <= 0.0 ) width = 0.0; @@ -30,7 +30,7 @@ void SoftPWM::start() { - _ticker.attach(this,&SoftPWM::TickerInterrapt,interval); + _ticker.attach(callback(this,&SoftPWM::TickerInterrapt),interval); } void SoftPWM::stop() @@ -43,7 +43,7 @@ wait(width); } -void SoftPWM::period(float _period) +void SoftPWM::period(double _period) { interval = _period; start(); @@ -51,17 +51,17 @@ void SoftPWM::period_ms(int _period) { - period((float)_period / 1000); + period((double)_period / 1000); start(); } void SoftPWM::period_us(int _period) { - period((float)_period / 1000000); + period((double)_period / 1000000); start(); } -void SoftPWM::pulsewidth(float _width) +void SoftPWM::pulsewidth(double _width) { width = _width; if ( width < 0.0 ) width = 0.0; @@ -69,18 +69,18 @@ void SoftPWM::pulsewidth_ms(int _width) { - pulsewidth((float)_width / 1000); + pulsewidth((double)_width / 1000); } void SoftPWM::pulsewidth_us(int _width) { - pulsewidth((float)_width / 1000000); + pulsewidth((double)_width / 1000000); } void SoftPWM::TickerInterrapt() { if ( width <= 0 ) return; - _timeout.attach(this,&SoftPWM::end,width); + _timeout.attach(callback(this,&SoftPWM::end),width); if ( positive ) pulse = 1; else