A fork of a fine man's work. simplified. No microstepping etc, just a work in progress

Fork of BipoarStepperMotor by Harsha vardan

Files at this revision

API Documentation at this revision

Comitter:
Harshavardan61
Date:
Mon Sep 23 14:32:02 2013 +0000
Parent:
1:d40368fd071e
Child:
3:944e51dd1e4c
Commit message:
C

Changed in this revision

sMotor.cpp Show diff for this revision Revisions of this file
sMotor.h Show diff for this revision Revisions of this file
stepperMotor.cpp Show annotated file Show diff for this revision Revisions of this file
stepperMotor.h Show annotated file Show diff for this revision Revisions of this file
--- a/sMotor.cpp	Mon Sep 23 14:29:54 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,173 +0,0 @@
-/*
-##############################################
-##    Program Created by Harshavardan61     ##
-##############################################
-        ---- harshavardan61@gmail.com -----
-        
-This library was made for 4-Phase Stepper Motors
-I don't take any resposability for the damage caused to your equipment.
-
-*/
-
-#include "sMotor.h"
-
-#include "mbed.h"
-
-int motorSpeed; // Steper speed
-
-sMotor::sMotor(PinName A0, PinName A1, PinName A2, PinName A3) : _A0(A0), _A1(A1), _A2(A2), _A3(A3) { // Defenition of motor pins
-    _A0=0;
-    _A1=0;
-    _A2=0;
-    _A3=0;
-}
-
-
-void sMotor::anticlockwise() { // 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
-            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() { // 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
-    if (direction==0) // turn clockwise
-        do {
-            clockwise();
-            count++;
-        } while (count<num_steps); // turn number of steps applied 
-    else if (direction==1)// turn anticlockwise
-        do {
-            anticlockwise();
-            count++;
-        } while (count<num_steps);// turn number of steps applied 
-
-}
\ No newline at end of file
--- a/sMotor.h	Mon Sep 23 14:29:54 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,35 +0,0 @@
-/*
-##############################################
-##    Program Created by Harshavardan61     ##
-##############################################
-        ---- harshavardan61@gmail.com -----
-        
-This library was made for 4-Phase Stepper Motors
-I don't take any resposability for the damage caused to your equipment.
-
-*/
-#ifndef MBED_SMOTOR_H
-#define MBED_SMOTOR_H
-
-#include "mbed.h"
-
-class sMotor {
-public:
-
-    sMotor(PinName A0, PinName A1, PinName A2, PinName A3); //motor constructor
-
-    void step(int num_steps, int direction, int speed);
-    void anticlockwise();
-    void clockwise();
-
-
-private:
-
-    DigitalOut _A0;
-    DigitalOut _A1;
-    DigitalOut _A2;
-    DigitalOut _A3;
-
-};
-
-#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stepperMotor.cpp	Mon Sep 23 14:32:02 2013 +0000
@@ -0,0 +1,173 @@
+/*
+##############################################
+##    Program Created by Harshavardan61     ##
+##############################################
+        ---- harshavardan61@gmail.com -----
+        
+This library was made for 4-Phase Stepper Motors
+I don't take any resposability for the damage caused to your equipment.
+
+*/
+
+#include "sMotor.h"
+
+#include "mbed.h"
+
+int motorSpeed; // Steper speed
+
+sMotor::sMotor(PinName A0, PinName A1, PinName A2, PinName A3) : _A0(A0), _A1(A1), _A2(A2), _A3(A3) { // Defenition of motor pins
+    _A0=0;
+    _A1=0;
+    _A2=0;
+    _A3=0;
+}
+
+
+void sMotor::anticlockwise() { // 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
+            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() { // 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
+    if (direction==0) // turn clockwise
+        do {
+            clockwise();
+            count++;
+        } while (count<num_steps); // turn number of steps applied 
+    else if (direction==1)// turn anticlockwise
+        do {
+            anticlockwise();
+            count++;
+        } while (count<num_steps);// turn number of steps applied 
+
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stepperMotor.h	Mon Sep 23 14:32:02 2013 +0000
@@ -0,0 +1,35 @@
+/*
+##############################################
+##    Program Created by Harshavardan61     ##
+##############################################
+        ---- harshavardan61@gmail.com -----
+        
+This library was made for 4-Phase Stepper Motors
+I don't take any resposability for the damage caused to your equipment.
+
+*/
+#ifndef MBED_SMOTOR_H
+#define MBED_SMOTOR_H
+
+#include "mbed.h"
+
+class sMotor {
+public:
+
+    sMotor(PinName A0, PinName A1, PinName A2, PinName A3); //motor constructor
+
+    void step(int num_steps, int direction, int speed);
+    void anticlockwise();
+    void clockwise();
+
+
+private:
+
+    DigitalOut _A0;
+    DigitalOut _A1;
+    DigitalOut _A2;
+    DigitalOut _A3;
+
+};
+
+#endif
\ No newline at end of file