yajuan yue / Mbed 2 deprecated ele350

Dependencies:   mbed

Fork of ele350 by JIAWEI ZHANG

soft_pwm.cpp

Committer:
GGHHHH
Date:
2015-11-05
Revision:
5:e820e1348f98
Parent:
3:1ad50b4e51a6
Child:
7:04e1552c7c95

File content as of revision 5:e820e1348f98:

#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){
        return true;
    }else {
        return false;
    }
}