Example to sweep a servo through its range

Dependencies:   Servo mbed

Fork of Servo_HelloWorld by Simon Ford

Files at this revision

API Documentation at this revision

Comitter:
woyao74le
Date:
Fri Jul 24 12:19:29 2015 +0000
Parent:
1:40d2fd0b99e6
Commit message:
Servo test

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- 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);
+        }
     }
 }
--- a/mbed.bld	Tue Nov 23 16:10:35 2010 +0000
+++ b/mbed.bld	Fri Jul 24 12:19:29 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/e2ac27c8e93e
+http://mbed.org/users/mbed_official/code/mbed/builds/da0ca467f8b5
\ No newline at end of file