Own PWM lib

Files at this revision

API Documentation at this revision

Comitter:
Drohne
Date:
Sun Apr 10 11:42:37 2016 +0000
Commit message:
PWM

Changed in this revision

PWM.cpp Show annotated file Show diff for this revision Revisions of this file
PWM.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PWM.cpp	Sun Apr 10 11:42:37 2016 +0000
@@ -0,0 +1,13 @@
+#include "mbed.h"
+#include "PWM.h"
+
+PWM::PWM(PinName pin) : _pin(pin){
+        _pin = 0;
+    }
+    
+    void PWM::dutycycle(int period, int ontime){
+                            _pin = 0;
+                            wait_us(ontime);            // ontime
+                            _pin = 1;
+                            wait_us(period-ontime);     // offtime
+            }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PWM.h	Sun Apr 10 11:42:37 2016 +0000
@@ -0,0 +1,14 @@
+#ifndef MBED_PWM_H
+#define MBED_PWM_H
+
+#include "mbed.h"
+
+class PWM {
+    public:
+        PWM(PinName pin);
+        void dutycycle(int period, int ontime);
+        
+    private:
+        DigitalOut _pin;
+    };
+#endif 
\ No newline at end of file