Bob Merrison-Hort
/
elec350
elec350
Fork of elec350 by
Diff: soft_pwm.cpp
- Revision:
- 10:021f19a9861f
- Child:
- 11:4685f33a2468
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/soft_pwm.cpp Wed Oct 21 19:52:30 2015 +0000 @@ -0,0 +1,32 @@ +#include "soft_pwm.h" + +SoftPwm::SoftPwm(float initialPeriod, float initialDutyCycle) +{ + this->period = initialPeriod; + this->dutyCycle = initialDutyCycle; + this->timer.start(); +} + +void SoftPwm::setPeriod(float newPeriod) +{ + this->period = newPeriod; +} + +void SoftPwm::setDutyCycle(float newDutyCycle) +{ + this->dutyCycle = newDutyCycle; +} + +bool SoftPwm::isOn() +{ + float phase = this->timer.read() / this->period; + if (phase > 1) { + this->timer.reset(); + } + if (phase < this->dutyCycle) { + return true; + } else { + return false; + } +} + \ No newline at end of file