Program for controlling stepper motors with threads.

Dependencies:   mbed-rtos mbed

Fork of L298N_Stepper_4wire_example by L298N Driver

Revision:
0:bd78e433db61
Child:
1:a3287196a9b3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Feb 29 12:10:54 2016 +0000
@@ -0,0 +1,75 @@
+#include "mbed.h"
+
+
+DigitalOut IN1(D3);
+DigitalOut IN2(D4);
+
+DigitalOut IN3(D5);
+DigitalOut IN4(D6);
+
+
+DigitalIn  SW(USER_BUTTON);
+
+void step4Right()
+{
+    IN1=0;
+    IN2=1;
+    IN3=0;
+    IN4=1;
+    wait_us(1000);
+    IN1=0;
+    IN2=1;
+    IN3=1;
+    IN4=0;
+    wait_us(1000);
+    IN1=1;
+    IN2=0;
+    IN3=1;
+    IN4=0;
+    wait_us(1000);
+    IN1=1;
+    IN2=0;
+    IN3=0;
+    IN4=1;
+    wait_us(1000);
+}
+
+
+void step4Left()
+{
+    IN1=1;
+    IN2=0;
+    IN3=0;
+    IN4=1;
+    wait_us(1000);
+
+    IN1=1;
+    IN2=0;
+    IN3=1;
+    IN4=0;
+    wait_us(1000);
+
+    IN1=0;
+    IN2=1;
+    IN3=1;
+    IN4=0;
+    wait_us(1000);
+
+    IN1=0;
+    IN2=1;
+    IN3=0;
+    IN4=1;
+    wait_us(1000);
+}
+
+
+int main()
+{
+    while (true) {
+        if(SW==1)
+            step4Left();
+        else
+            step4Right();
+
+    }
+}
\ No newline at end of file