Credit for the author

Dependents:   Stepper_4

Fork of sMotor by Nuno Sarmento

Files at this revision

API Documentation at this revision

Comitter:
zchen311
Date:
Sat Sep 20 14:48:34 2014 +0000
Parent:
0:4b3b9e047ce3
Commit message:
modify

Changed in this revision

sMotor.cpp Show annotated file Show diff for this revision Revisions of this file
sMotor.h Show annotated file Show diff for this revision Revisions of this file
diff -r 4b3b9e047ce3 -r cf4869aef47f sMotor.cpp
--- a/sMotor.cpp	Thu Jun 14 12:16:40 2012 +0000
+++ b/sMotor.cpp	Sat Sep 20 14:48:34 2014 +0000
@@ -23,10 +23,78 @@
 }
 
 
-void sMotor::anticlockwise() { // rotate the motor 1 step anticlockwise 
-    for (int i = 0; i < 8; i++) {
+void sMotor::anticlockwise(int current_step) { // rotate the motor 1 step anticlockwise 
+    
+    //for (int i = 0; i < 8; i++) {
 
-        switch (i) { // activate the ports A0, A2, A3, A3 in a binary sequence for steps
+        switch (current_step) { // activate the ports A0, A2, A3, A3 in a binary sequence for steps
+            case 0: {
+                _A0=0;
+                _A1=0;
+                _A2=0;
+                _A3=1;
+            }
+            //break;
+            case 1: {
+                _A0=0;
+                _A1=0;
+                _A2=1;
+                _A3=1;
+            }
+            //break;
+            case 2: {
+                _A0=0;
+                _A1=0;
+                _A2=1;
+                _A3=0;
+            }
+            //break;
+            case 3: {
+                _A0=0;
+                _A1=1;
+                _A2=1;
+                _A3=0;
+            }
+            //break;
+            case 4: {
+                _A0=0;
+                _A1=1;
+                _A2=0;
+                _A3=0;
+            }
+            //break;
+            case 5: {
+                _A0=1;
+                _A1=1;
+                _A2=0;
+                _A3=0;
+            }
+            //break;
+            case 6: {
+                _A0=1;
+                _A1=0;
+                _A2=0;
+                _A3=0;
+            }
+            //break;
+            case 7: {
+                _A0=1;
+                _A1=0;
+                _A2=0;
+                _A3=1;
+            }
+          //  break;
+        //}
+
+
+        wait_us(motorSpeed); // wait time defines the speed 
+    }
+}
+
+void sMotor::clockwise(int current_step) { // rotate the motor 1 step clockwise 
+    //for (int i = 7; i >= 0; i--) {
+
+        switch (current_step) {
             case 0: {
                 _A0=0;
                 _A1=0;
@@ -88,74 +156,7 @@
 
         wait_us(motorSpeed); // wait time defines the speed 
     }
-}
-
-void sMotor::clockwise() { // rotate the motor 1 step clockwise 
-    for (int i = 7; i >= 0; i--) {
-
-        switch (i) {
-            case 0: {
-                _A0=0;
-                _A1=0;
-                _A2=0;
-                _A3=1;
-            }
-            break;
-            case 1: {
-                _A0=0;
-                _A1=0;
-                _A2=1;
-                _A3=1;
-            }
-            break;
-            case 2: {
-                _A0=0;
-                _A1=0;
-                _A2=1;
-                _A3=0;
-            }
-            break;
-            case 3: {
-                _A0=0;
-                _A1=1;
-                _A2=1;
-                _A3=0;
-            }
-            break;
-            case 4: {
-                _A0=0;
-                _A1=1;
-                _A2=0;
-                _A3=0;
-            }
-            break;
-            case 5: {
-                _A0=1;
-                _A1=1;
-                _A2=0;
-                _A3=0;
-            }
-            break;
-            case 6: {
-                _A0=1;
-                _A1=0;
-                _A2=0;
-                _A3=0;
-            }
-            break;
-            case 7: {
-                _A0=1;
-                _A1=0;
-                _A2=0;
-                _A3=1;
-            }
-            break;
-        }
-
-
-        wait_us(motorSpeed); // wait time defines the speed 
-    }
-}
+//}
 void sMotor::step(int num_steps, int direction, int speed) {// steper function: number of steps, direction (0- right, 1- left), speed (default 1200)
     int count=0; // initalize step count
     motorSpeed=speed; //set motor speed
@@ -170,4 +171,143 @@
             count++;
         } while (count<num_steps);// turn number of steps applied 
 
+}
+
+
+void sMotor::anticlockwise(int current_step) { // rotate the motor 1 step anticlockwise 
+    
+    //for (int i = 0; i < 8; i++) {
+
+        switch (current_step) { // activate the ports A0, A2, A3, A3 in a binary sequence for steps
+            case 0: {
+                _A0=0;
+                _A1=0;
+                _A2=0;
+                _A3=1;
+            }
+            //break;
+            case 1: {
+                _A0=0;
+                _A1=0;
+                _A2=1;
+                _A3=1;
+            }
+            //break;
+            case 2: {
+                _A0=0;
+                _A1=0;
+                _A2=1;
+                _A3=0;
+            }
+            //break;
+            case 3: {
+                _A0=0;
+                _A1=1;
+                _A2=1;
+                _A3=0;
+            }
+            //break;
+            case 4: {
+                _A0=0;
+                _A1=1;
+                _A2=0;
+                _A3=0;
+            }
+            //break;
+            case 5: {
+                _A0=1;
+                _A1=1;
+                _A2=0;
+                _A3=0;
+            }
+            //break;
+            case 6: {
+                _A0=1;
+                _A1=0;
+                _A2=0;
+                _A3=0;
+            }
+            //break;
+            case 7: {
+                _A0=1;
+                _A1=0;
+                _A2=0;
+                _A3=1;
+            }
+          //  break;
+        //}
+
+
+        wait_us(motorSpeed); // wait time defines the speed 
+    }
+}
+
+void sMotor::stop(int current_step) { // rotate the motor 1 step clockwise 
+    //for (int i = 7; i >= 0; i--) {
+
+        switch (current_step) {
+            case 1: {
+                _A0=0;
+                _A1=0;
+                _A2=0;
+                _A3=1;
+            }
+            break;
+            case 2: {
+                _A0=0;
+                _A1=0;
+                _A2=1;
+                _A3=1;
+            }
+            break;
+            case 3: {
+                _A0=0;
+                _A1=0;
+                _A2=1;
+                _A3=0;
+            }
+            break;
+            case 4: {
+                _A0=0;
+                _A1=1;
+                _A2=1;
+                _A3=0;
+            }
+            break;
+            case 5: {
+                _A0=0;
+                _A1=1;
+                _A2=0;
+                _A3=0;
+            }
+            break;
+            case 6: {
+                _A0=1;
+                _A1=1;
+                _A2=0;
+                _A3=0;
+            }
+            break;
+            case 7: {
+                _A0=1;
+                _A1=0;
+                _A2=0;
+                _A3=0;
+            }
+            break;
+            case 0: {
+                _A0=1;
+                _A1=0;
+                _A2=0;
+                _A3=1;
+            }
+            break;
+        }
+
+
+        wait_us(motorSpeed); // wait time defines the speed 
+    }
+    
+void sMotor::delay(int delay_time){
+    wait_us(delay_time);   
 }
\ No newline at end of file
diff -r 4b3b9e047ce3 -r cf4869aef47f sMotor.h
--- a/sMotor.h	Thu Jun 14 12:16:40 2012 +0000
+++ b/sMotor.h	Sat Sep 20 14:48:34 2014 +0000
@@ -19,9 +19,10 @@
     sMotor(PinName A0, PinName A1, PinName A2, PinName A3); //motor constructor
 
     void step(int num_steps, int direction, int speed);
-    void anticlockwise();
-    void clockwise();
-
+    void anticlockwise(int current_step);
+    void clockwise(int current_step);
+    void stop(step);
+    void delay(int delay_time);
 
 private: