Met servo motor

Dependencies:   MODSERIAL QEI mbed

Fork of Switch_motoren_motoren by Lian Beenhakker

Files at this revision

API Documentation at this revision

Comitter:
lisa96m
Date:
Fri Oct 28 07:44:01 2016 +0000
Parent:
1:52a95e4b5662
Commit message:
Aansturing motoren met servo geimplementeerd;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 52a95e4b5662 -r 725188195139 main.cpp
--- a/main.cpp	Wed Oct 26 07:41:27 2016 +0000
+++ b/main.cpp	Fri Oct 28 07:44:01 2016 +0000
@@ -17,6 +17,9 @@
 //QEI Encoder1(D10, D11, NC, 32); // met encoder onthouden waar je bent
 //QEI Encoder2(D12, D13, NC, 32); // met encoder onthouden waar je bent
 
+//Pin voor de servo
+PwmOut servo(D9);
+
 //Define variables
 volatile int indrukken = 0;
 volatile int i = 0;
@@ -112,6 +115,25 @@
     }
 }
 
+void SetMotor3(float MV)
+{
+    if (MV > 0)
+        {
+            servo = 0.04;
+            pc.printf("servo = 0.01\n\r"); //De servo draait maximaal rechtsom de klep dus open
+        }
+    else if (MV = 0)
+        {
+            servo = servo;
+            pc.printf("servo = servo\n\r");
+        }
+    else (MV < 0)
+        {
+            servo = 0.08;
+            pc.printf("servo = 0.15\n\r");
+        }
+}
+
 void MeasureAndControl()
 {
     float MV = GetMotorValue();
@@ -153,6 +175,7 @@
     Ticker motordraaien;
     motordraaien.attach(MeasureAndControl,2);
     Spier3.fall(count);
+    servo.period(0.020) //servo periode 20ms
     while(true){}  
 }