Sam Ewins / Mbed 2 deprecated Sound_Meter

Dependencies:   elec350 mbed

Revision:
0:cff19fd9a3be
diff -r 000000000000 -r cff19fd9a3be soft_pwn.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/soft_pwn.cpp	Wed Nov 04 21:47:34 2015 +0000
@@ -0,0 +1,40 @@
+#include "soft_pwm.h"
+
+SoftPwm::SoftPwm(float initialPeriod, float initialDutyCycle)
+{
+    this->period = initialPeriod;
+    this->dutyCycle = initialDutyCycle;
+
+    this->timer.start();
+}
+
+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;
+}
+
+bool SoftPwm::isOn()
+{
+    float onPhaseDuration = this->dutyCycle * this->period;
+    float currentTime = this->timer.read();
+    if (currentTime > this->period) {
+        this->timer.reset();
+    }
+    if (currentTime<onPhaseDuration) {
+        return true;
+    } else {
+        return false;
+    }
+}
\ No newline at end of file