pwm manijk

Files at this revision

API Documentation at this revision

Comitter:
mlucan
Date:
Mon Feb 10 09:12:35 2020 +0000
Parent:
0:526351bcb96b
Commit message:
PWM control

Changed in this revision

UpravljanjePWM.cpp Show annotated file Show diff for this revision Revisions of this file
UpravljanjePWM.h Show annotated file Show diff for this revision Revisions of this file
--- a/UpravljanjePWM.cpp	Tue Jan 21 12:11:26 2020 +0000
+++ b/UpravljanjePWM.cpp	Mon Feb 10 09:12:35 2020 +0000
@@ -1,38 +1,54 @@
 #include "UpravljanjePWM.h"
 #include "mbed.h"
 
-UpravljanjePWM::UpravljanjePWM(AnalogIn pin) : ain(pin) {};
-
-   float UpravljanjePWM::pwm1(bool onOff, bool smijer)
-    {
-        float pwm=0;
+bool smjer=false;
+bool onOff=false;
+void psmjera();
+void on_off();
+Timer debounce;
 
-        if(onOff==false) {
-            pwm=0;
+UpravljanjePWM::UpravljanjePWM(PinName pin1,PinName pin2, PinName pin3, PinName pin4, PinName pin5) : pwm1(pin1), pwm2(pin2), ain(pin3),int1(pin4), int2(pin5)
+{
+    pwm1.period(0.010);
+    pwm2.period(0.010);
+    debounce.start();
+    int1.rise(&psmjera);
+    int2.rise(&on_off);
 
-        } else {
-            if(smijer) {
-                pwm=ain;
-            } else {
-                pwm=0;
-            }
-        }
+};
 
-        return pwm;
-    }
-     float UpravljanjePWM::pwm2(bool onOff, bool smijer)
-    {
-        float pwm=0;
-        if(onOff==false) {
-            pwm=0;
-
+void UpravljanjePWM::pwm(float treshold)
+{
+    if(ain<treshold||onOff==false) {
+        pwm1=0;
+        pwm2=0;
+    } else {
+        if(smjer==false) {
+            pwm1=ain;
+            pwm2=0;
         } else {
-            if(smijer) {
-                pwm=0;
-            } else {
-                pwm=ain;
-            }
+            pwm1=0;
+            pwm2=ain;
         }
+    }
+}
 
-        return pwm;
-    }
\ No newline at end of file
+bool UpravljanjePWM::zadanismjervrtnje()
+{
+    return smjer;
+}
+
+void psmjera()
+{
+    if(debounce.read_ms()>200) {
+        smjer=!smjer;
+        debounce.reset();
+    }
+};
+void on_off()
+{
+    if(debounce.read_ms()>200) {
+        onOff=!onOff;
+        debounce.reset();
+    }
+};
--- a/UpravljanjePWM.h	Tue Jan 21 12:11:26 2020 +0000
+++ b/UpravljanjePWM.h	Mon Feb 10 09:12:35 2020 +0000
@@ -3,13 +3,20 @@
 
 #include "mbed.h"
 
-class UpravljanjePWM{
-    public:
-    UpravljanjePWM(AnalogIn pin);
-    float pwm1(bool onOff, bool smijer);
-    float pwm2(bool onOff, bool smijer);
-    
-    private:
+
+class UpravljanjePWM
+{
+public:
+    UpravljanjePWM(PinName pin1, PinName pin2, PinName pin3, PinName pin4, PinName pin5);
+    void pwm(float treshold);
+    bool zadanismjervrtnje();
+
+private:
     AnalogIn ain;
-    };
-    #endif 
\ No newline at end of file
+    PwmOut pwm1;
+    PwmOut pwm2;
+    InterruptIn int1;
+    InterruptIn int2;
+
+};
+#endif
\ No newline at end of file