L298N H-Bridge Stepper Motor Driver

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
Spilly
Date:
Tue Mar 17 01:14:23 2015 +0000
Commit message:
L298N H-Bridge Controlling Stepper

Changed in this revision

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
diff -r 000000000000 -r 1b228aff0bda main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Mar 17 01:14:23 2015 +0000
@@ -0,0 +1,183 @@
+#include "mbed.h"
+/*
+#define ENA 8
+#define ENB 13
+
+#define black 9  // In1
+#define brown 10  // In2
+#define orange 11  // In3
+#define yellow 12  // In4
+*/
+//L298n connections
+DigitalOut pinI1(D5);
+DigitalOut pinI2(D6);
+DigitalOut pinI3(D10);
+DigitalOut pinI4(D11);
+DigitalOut ENA(D12);    //Left
+DigitalOut ENB(D13);    //Right
+
+void forward(int i, float j);
+void reverse(int i, float j);
+
+int main()
+{
+    while (true) 
+    {
+        forward(100, 0.003f);
+        //wait(1.0f);
+        //reverse(10, 0.1f);
+        //wait(1.0f);
+    }
+}
+
+void reverse(int i, float j) 
+{
+
+    // Pin 8 Enable A Pin 13 Enable B on
+    //digitalWrite(ENA, HIGH);
+    ENA = 1;
+    //digitalWrite(ENB, HIGH);
+    ENB = 1;
+    
+    //j = j + .010f;
+    while (1)   {
+    
+    //digitalWrite(black, 0);
+    //digitalWrite(brown, 1);
+    //digitalWrite(orange, 1);
+    //digitalWrite(yellow, 0);
+    pinI1 = 0;
+    pinI2 = 1;
+    pinI3 = 1;
+    pinI4 = 0;
+    
+    wait(j);  
+    i--;
+    if (i < 1) break;
+    
+    /*
+    digitalWrite(black, 0);
+    digitalWrite(brown, 1);
+    digitalWrite(orange, 0);
+    digitalWrite(yellow, 1);
+    */
+    pinI1 = 0;
+    pinI2 = 1;
+    pinI3 = 0;
+    pinI4 = 1;
+    wait(j);
+    i--;
+    if (i < 1) break;
+    
+    /*
+    digitalWrite(black, 1);
+    digitalWrite(brown, 0);
+    digitalWrite(orange, 0);
+    digitalWrite(yellow, 1);
+    */
+    pinI1 = 1;
+    pinI2 = 0;
+    pinI3 = 0;
+    pinI4 = 1;
+    wait(j);  
+    i--;
+    if (i < 1) break;
+    /*
+    digitalWrite(black, 1);
+    digitalWrite(brown, 0);
+    digitalWrite(orange, 1);
+    digitalWrite(yellow, 0);
+    */
+    pinI1 = 1;
+    pinI2 = 0;
+    pinI3 = 1;
+    pinI4 = 0;
+    wait(j);
+    i--;
+    if (i < 1) break;
+    }
+    
+    // all outputs to stepper off
+    //digitalWrite(ENA, LOW);
+    //digitalWrite(ENB, LOW);
+    ENA = 0;
+    ENB = 0;
+}
+
+
+
+void forward(int i, float j) 
+{
+
+    // Pin 8 Enable A Pin 13 Enable B on
+    //digitalWrite(ENA, HIGH);
+    //digitalWrite(ENB, HIGH);
+    ENA = 1;
+    ENB = 1;
+    
+    //j = j + .010f;
+    while (1)   {
+    /*
+    digitalWrite(black, 1);
+    digitalWrite(brown, 0);
+    digitalWrite(orange, 1);
+    digitalWrite(yellow, 0);
+    */
+    pinI1 = 1;
+    pinI2 = 0;
+    pinI3 = 1;
+    pinI4 = 0;
+    wait(j);
+    i--;
+    if (i < 1) break; 
+    
+    
+    /*
+    digitalWrite(black, 1);
+    digitalWrite(brown, 0);
+    digitalWrite(orange, 0);
+    digitalWrite(yellow, 1);
+    */
+    pinI1 = 1;
+    pinI2 = 0;
+    pinI3 = 0;
+    pinI4 = 1;
+    wait(j);  
+    i--;
+    if (i < 1) break;
+    /*
+    digitalWrite(black, 0);
+    digitalWrite(brown, 1);
+    digitalWrite(orange, 0);
+    digitalWrite(yellow, 1);
+    */
+    pinI1 = 0;
+    pinI2 = 1;
+    pinI3 = 0;
+    pinI4 = 1;
+    wait(j);
+    i--;
+    if (i < 1) break;
+    /*
+    digitalWrite(black, 0);
+    digitalWrite(brown, 1);
+    digitalWrite(orange, 1);
+    digitalWrite(yellow, 0);
+    */
+    pinI1 = 0;
+    pinI2 = 1;
+    pinI3 = 1;
+    pinI4 = 0;
+    wait(j);  
+    i--;
+    if (i < 1) break;
+    
+    
+    }
+    
+    // all outputs to stepper off
+    //digitalWrite(ENA, LOW);
+    //digitalWrite(ENB, LOW);
+    ENA = 0;
+    ENB = 0;
+}
\ No newline at end of file
diff -r 000000000000 -r 1b228aff0bda mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Mar 17 01:14:23 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/7e07b6fb45cf
\ No newline at end of file