Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of ele350 by
soft_pwm.cpp
- Committer:
- yyue
- Date:
- 2016-10-18
- Revision:
- 7:04e1552c7c95
- Parent:
- 5:e820e1348f98
File content as of revision 7:04e1552c7c95:
#include "soft_pwm.h" float SoftPwm::getPeriod() { return this->period; } float SoftPwm::getDutyCycle() { return this->dutyCycle; } void SoftPwm::setPeriod(float newPeriod) { this->period = newPeriod; } void SoftPwm::setDutyCycle(float newDutyCycle) { this->dutyCycle = newDutyCycle; } SoftPwm::SoftPwm(float initialPeriod, float initialDutyCycle) { this->period = initialPeriod; this->dutyCycle = initialDutyCycle; this->timer.start(); } bool SoftPwm::isOn() { float onPhaseDuration = this->dutyCycle * this->period; float currentTime = this->timer.read(); if (currentTime > onPhaseDuration){ this->timer.start(); } if (currentTime < onPhaseDuration){ return true; }else { return false; } }