softwarePWM by ticker, timer

Dependents:   Seeed_Motor_Shield_HelloWorld Official_MedusaIcon Seeed_Motor_Shield adrobo

Revision:
0:1e86036581bd
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SoftwarePWM.cpp	Thu Apr 05 07:09:39 2012 +0000
@@ -0,0 +1,30 @@
+#include "SoftwarePWM.h"
+#include "mbed.h"
+
+SoftwarePWM::SoftwarePWM(PinName Pin) : SoftwarePWMPin(Pin) {}
+
+void SoftwarePWM::SetPosition(int Pos) {
+    Position = Pos;
+}
+
+void SoftwarePWM::StartPulse() {
+    if(Position <= 0) {
+        SoftwarePWMPin = 0 ;
+    } else {
+        SoftwarePWMPin = 1;
+        PulseStop.attach_us(this, &SoftwarePWM::EndPulse, Position);
+    }
+}
+
+void SoftwarePWM::EndPulse() {
+    SoftwarePWMPin = 0;
+}
+
+void SoftwarePWM::Enable(int StartPos, int Period) {
+    Position = StartPos;
+    Pulse.attach_us(this, &SoftwarePWM::StartPulse, Period);
+}
+
+void SoftwarePWM::Disable() {
+    Pulse.detach();
+}
\ No newline at end of file