Control a servo with an analog value (knob). A basic example of using a servo.

Dependencies:   Servo mbed

Files at this revision

API Documentation at this revision

Comitter:
jose_23991
Date:
Fri Sep 19 15:26:02 2014 +0000
Commit message:
Version 1.0

Changed in this revision

Servo.lib Show annotated file Show diff for this revision Revisions of this file
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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Servo.lib	Fri Sep 19 15:26:02 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/Servo/#36b69a7ced07
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Sep 19 15:26:02 2014 +0000
@@ -0,0 +1,19 @@
+#include "mbed.h"
+#include "Servo.h"
+
+int main()
+{
+    Servo myservo(D3);                // Create the servo object
+    AnalogIn knob(A0);                // Create the analog input object
+    
+    float val;
+    
+    myservo.calibrate(0.00095, 90.0); // Calibrate the servo
+        
+    while(1)
+    {
+        val = knob.read();            // Reads the value of the potentiometer (value between 0 and 1) 
+        myservo.write(val);           // Sets the servo position according to the scaled value  (0-1)
+        wait_ms(15);                  // Waits for the servo to get there 
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Sep 19 15:26:02 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/552587b429a1
\ No newline at end of file