yajuan yue / Mbed 2 deprecated ele350

Dependencies:   mbed

Fork of ele350 by JIAWEI ZHANG

Committer:
GGHHHH
Date:
Thu Nov 05 12:01:26 2015 +0000
Revision:
3:1ad50b4e51a6
Child:
5:e820e1348f98
ku

Who changed what in which revision?

UserRevisionLine numberNew contents of line
GGHHHH 3:1ad50b4e51a6 1 #include "soft_pwm.h"
GGHHHH 3:1ad50b4e51a6 2
GGHHHH 3:1ad50b4e51a6 3
GGHHHH 3:1ad50b4e51a6 4 float SoftPwm::getPeriod()
GGHHHH 3:1ad50b4e51a6 5 {
GGHHHH 3:1ad50b4e51a6 6 return this->period;
GGHHHH 3:1ad50b4e51a6 7 }
GGHHHH 3:1ad50b4e51a6 8
GGHHHH 3:1ad50b4e51a6 9 float SoftPwm::getDutyCycle()
GGHHHH 3:1ad50b4e51a6 10 {
GGHHHH 3:1ad50b4e51a6 11 return this->dutyCycle;
GGHHHH 3:1ad50b4e51a6 12 }
GGHHHH 3:1ad50b4e51a6 13
GGHHHH 3:1ad50b4e51a6 14 void SoftPwm::setPeriod(float newPeriod)
GGHHHH 3:1ad50b4e51a6 15 {
GGHHHH 3:1ad50b4e51a6 16 this->period = newPeriod;
GGHHHH 3:1ad50b4e51a6 17 }
GGHHHH 3:1ad50b4e51a6 18
GGHHHH 3:1ad50b4e51a6 19 void SoftPwm::setDutyCycle(float newDutyCycle)
GGHHHH 3:1ad50b4e51a6 20 {
GGHHHH 3:1ad50b4e51a6 21 this->dutyCycle = newDutyCycle;
GGHHHH 3:1ad50b4e51a6 22 }
GGHHHH 3:1ad50b4e51a6 23 SoftPwm::SoftPwm(float initialPeriod, float initialDutyCycle)
GGHHHH 3:1ad50b4e51a6 24 {
GGHHHH 3:1ad50b4e51a6 25
GGHHHH 3:1ad50b4e51a6 26 this->period = initialPeriod;
GGHHHH 3:1ad50b4e51a6 27 this->dutyCycle = initialDutyCycle;
GGHHHH 3:1ad50b4e51a6 28
GGHHHH 3:1ad50b4e51a6 29 pwm.setDutyCycle((1.0f+sin(breathingTimer.read()*M_PI))/2.0f);
GGHHHH 3:1ad50b4e51a6 30 this->timer.start();
GGHHHH 3:1ad50b4e51a6 31
GGHHHH 3:1ad50b4e51a6 32 bool SoftPwm::isOn()
GGHHHH 3:1ad50b4e51a6 33
GGHHHH 3:1ad50b4e51a6 34 float onPhaseDuration = this->dutyCycle * this->period;
GGHHHH 3:1ad50b4e51a6 35 float currentTime = this->timer.reset();
GGHHHH 3:1ad50b4e51a6 36
GGHHHH 3:1ad50b4e51a6 37 if (currentTime < onPhaseDuration){
GGHHHH 3:1ad50b4e51a6 38 return true;
GGHHHH 3:1ad50b4e51a6 39 }else {
GGHHHH 3:1ad50b4e51a6 40 return false;
GGHHHH 3:1ad50b4e51a6 41 }
GGHHHH 3:1ad50b4e51a6 42 }