Chad Lewellyn / Mbed 2 deprecated Lab3part3

Dependencies:   Motor Servo mbed

Fork of Lab_3_part3 by Chad Lewellyn

Files at this revision

API Documentation at this revision

Comitter:
chadlewellyn
Date:
Wed Oct 14 00:05:01 2015 +0000
Parent:
0:18862eeb0ae8
Commit message:
part 3

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 18862eeb0ae8 -r 5316305f313a main.cpp
--- a/main.cpp	Tue Oct 13 13:58:01 2015 +0000
+++ b/main.cpp	Wed Oct 14 00:05:01 2015 +0000
@@ -5,35 +5,35 @@
 
 int main() {
 
-float i;
-Servo myservo1(p21);
-myservo1 = 0;
-myservo1.calibrate(0.0009, 90);
-Servo myservo2(p22);
-myservo2 = 0;
-myservo2.calibrate(0.0009, 90);
+float i;                           //float variable
+Servo myservo1(p21);               //servo motor connected to pin 21
+myservo1 = 0;                      //set initially to 0
+myservo1.calibrate(0.0009, 90);    //calibrate starting point and angle
+Servo myservo2(p22);               //servo motor connected to pin 22
+myservo2 = 0;                      //set initially to 0
+myservo2.calibrate(0.0009, 90);    //calibrate starting point and angle
 
-while(1) {
-for (i = 0; i <= 1.0; i+=0.01) {
-    myservo1 = i;
-    myservo2 = 1.0 - i;
-    wait(.05);
+while(1) {                         //while loop
+for (i = 0; i <= 1.0; i+=0.01) {   //increases integer by .01 until it reaches 1
+    myservo1 = i;                  //set first servo to turn one way
+    myservo2 = 1.0 - i;            //second servo turns the other way
+    wait(.05);                     //wait .05 seconds
     }
-for (i = 1.0; i >= 0; i-=0.01) {
-    myservo1 = i;
-    myservo2 = 1.0 - i;
-    wait(.05);
+for (i = 1.0; i >= 0; i-=0.01) {   //decrease integer by .01 until it reaches 0
+    myservo1 = i;                  //set first servo to turn one way
+    myservo2 = 1.0 - i;            //second servo turns the other way
+    wait(.05);                     //wait .05 seconds
     }
     
-Motor m(p25, p27, p28);
-float s, n;
+Motor m(p25, p27, p28);            //motor listens to pins 25, 27, and 28
+float s, n;                        //assign two float integers
 
-for (s = 0.2; s <= 1.0; += 0.1) {
-    n = -s;
-    m.speed(s);
-    wait(5);
-    m.speed(n);
-    wait(5);
+for (s = 0.2; s <= 1.0; += 0.1) {  //motor increseas in speed until it reaches 1
+    n = -s;                        
+    m.speed(s);                    //motor spins at a speed that corrilates to float s
+    wait(5);                       //wait 5 seconds
+    m.speed(n);                    //motor spins in opposite direction but same speed
+    wait(5);                       //wait 5 seconds
     }    
     
 }