
elec350
Fork of elec350 by
soft_pwm.cpp
- Committer:
- rmerrisonhort
- Date:
- 2015-10-21
- Revision:
- 10:021f19a9861f
- Child:
- 11:4685f33a2468
File content as of revision 10:021f19a9861f:
#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; } }