Example to sweep a servo through its range

Dependencies:   Servo mbed

Fork of Servo_HelloWorld by Simon Ford

Revision:
2:7911e5580e4e
Parent:
1:40d2fd0b99e6
--- a/main.cpp	Tue Nov 23 16:10:35 2010 +0000
+++ b/main.cpp	Fri Jul 24 12:19:29 2015 +0000
@@ -1,13 +1,24 @@
 // Hello World to sweep a servo through its full range
 
 #include "mbed.h"
-#include "Servo.h"
+
+PwmOut PWM1(PA_1);
 
-Servo myservo(p21);
+int main()
+{
 
-int main() {    
-    for(float p=0; p<1.0; p += 0.1) {
-        myservo = p;
-        wait(0.2);
+    PWM1.period(0.02);
+    while(1)
+    {
+        for (float i=0.025; i<0.04; i=i+0.001)
+        {
+            PWM1=i;
+            wait(0.02);
+        }
+        for (float i=0.04; i>0.025; i=i-0.001)
+        {
+            PWM1=i;
+            wait(0.02);
+        }
     }
 }