Servo Motor

Dependencies:   Servo mbed

Fork of Servo_HelloWorld by Simon Ford

Revision:
2:115ddb84b970
Parent:
1:40d2fd0b99e6
--- a/main.cpp	Tue Nov 23 16:10:35 2010 +0000
+++ b/main.cpp	Thu Oct 26 13:46:52 2017 +0000
@@ -1,13 +1,21 @@
-// Hello World to sweep a servo through its full range
-
 #include "mbed.h"
 #include "Servo.h"
 
-Servo myservo(p21);
+Serial rs232(USBTX, USBRX);
+Servo servomotor(PTE29); // PIN PWM
+int grados,k;
 
-int main() {    
-    for(float p=0; p<1.0; p += 0.1) {
-        myservo = p;
-        wait(0.2);
+int main()
+{
+    rs232.baud(9600);
+    while(1) {
+        grados=0;k=0;
+        for(float i=0; i<1.0; i += 0.08333) { // 12 pasos de 15° (0 a 180° entre 0 y 1.0 mseg: 0.08333mseg por paso)
+            servomotor = i;
+            wait(0.5);
+            grados=k*15;
+            rs232.printf("%d \r\n",grados); //Visualiza avance cada 15°
+            ++k;
+        }
     }
 }