Servo

Dependencies:   mbed MODSERIAL Servo FastPWM

Revision:
10:1754b6220c7a
Parent:
8:3990a8c4ccea
Child:
11:bb036c288cd7
diff -r 3990a8c4ccea -r 1754b6220c7a main.cpp
--- a/main.cpp	Mon Oct 28 16:50:36 2019 +0000
+++ b/main.cpp	Mon Oct 28 17:18:32 2019 +0000
@@ -1,31 +1,29 @@
+
+#include "Servo.h"
 #include "mbed.h"
-//#include "Servo.h"
-//#include "FastPWM.h"
-#include <math.h>
-#include "Servo.h"
+#include "FastPWM.h"
 
 Serial pc(USBTX, USBRX);
-//PwmOut myservo(D5);
-//DigitalIn servo_button_pressed(D0);
-
-Servo servo1 (D7); // kan nog aangepast worden de pin
-//servo1.Enable(1500,20000);
-int pos(); 
-int main()
-{
-
-
-while(1) {
-     for (int pos = 1000; pos < 2000; pos += 25) {
-         servo1.SetPosition(pos);  
-         wait_ms(20);
-     }
-     for (int pos = 2000; pos > 1000; pos -= 25) {
-         servo1.SetPosition(pos); 
-         wait_ms(20); 
-     }
- }
-}
-
-
-    
\ No newline at end of file
+Servo mijnServo(D7);
+double pos = 0;
+double target;
+int main(void)
+{mijnServo.Enable(1500,20000);
+    wait(1);
+    for(pos = 2400; pos >=500; pos-=50)
+    {
+        target = pos/180;
+        mijnServo.SetPosition(pos);
+        pc.printf("De servo staat op %f graden.\n\r", pos);
+        wait(0.1);
+    }
+    for(pos = 500; pos <= 2400; pos += 50)
+    {
+        target = pos/180;
+        mijnServo.SetPosition(pos);
+        pc.printf("De servo staat op %f graden.\n\r", pos);
+        wait(0.1);
+    } 
+    while(true);
+   
+}
\ No newline at end of file