Program for controlling stepper motors with threads.

Dependencies:   mbed-rtos mbed

Fork of L298N_Stepper_4wire_example by L298N Driver

Committer:
rlanghbv
Date:
Mon Feb 29 12:10:54 2016 +0000
Revision:
0:bd78e433db61
Child:
1:a3287196a9b3
Firtst Commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rlanghbv 0:bd78e433db61 1 #include "mbed.h"
rlanghbv 0:bd78e433db61 2
rlanghbv 0:bd78e433db61 3
rlanghbv 0:bd78e433db61 4 DigitalOut IN1(D3);
rlanghbv 0:bd78e433db61 5 DigitalOut IN2(D4);
rlanghbv 0:bd78e433db61 6
rlanghbv 0:bd78e433db61 7 DigitalOut IN3(D5);
rlanghbv 0:bd78e433db61 8 DigitalOut IN4(D6);
rlanghbv 0:bd78e433db61 9
rlanghbv 0:bd78e433db61 10
rlanghbv 0:bd78e433db61 11 DigitalIn SW(USER_BUTTON);
rlanghbv 0:bd78e433db61 12
rlanghbv 0:bd78e433db61 13 void step4Right()
rlanghbv 0:bd78e433db61 14 {
rlanghbv 0:bd78e433db61 15 IN1=0;
rlanghbv 0:bd78e433db61 16 IN2=1;
rlanghbv 0:bd78e433db61 17 IN3=0;
rlanghbv 0:bd78e433db61 18 IN4=1;
rlanghbv 0:bd78e433db61 19 wait_us(1000);
rlanghbv 0:bd78e433db61 20 IN1=0;
rlanghbv 0:bd78e433db61 21 IN2=1;
rlanghbv 0:bd78e433db61 22 IN3=1;
rlanghbv 0:bd78e433db61 23 IN4=0;
rlanghbv 0:bd78e433db61 24 wait_us(1000);
rlanghbv 0:bd78e433db61 25 IN1=1;
rlanghbv 0:bd78e433db61 26 IN2=0;
rlanghbv 0:bd78e433db61 27 IN3=1;
rlanghbv 0:bd78e433db61 28 IN4=0;
rlanghbv 0:bd78e433db61 29 wait_us(1000);
rlanghbv 0:bd78e433db61 30 IN1=1;
rlanghbv 0:bd78e433db61 31 IN2=0;
rlanghbv 0:bd78e433db61 32 IN3=0;
rlanghbv 0:bd78e433db61 33 IN4=1;
rlanghbv 0:bd78e433db61 34 wait_us(1000);
rlanghbv 0:bd78e433db61 35 }
rlanghbv 0:bd78e433db61 36
rlanghbv 0:bd78e433db61 37
rlanghbv 0:bd78e433db61 38 void step4Left()
rlanghbv 0:bd78e433db61 39 {
rlanghbv 0:bd78e433db61 40 IN1=1;
rlanghbv 0:bd78e433db61 41 IN2=0;
rlanghbv 0:bd78e433db61 42 IN3=0;
rlanghbv 0:bd78e433db61 43 IN4=1;
rlanghbv 0:bd78e433db61 44 wait_us(1000);
rlanghbv 0:bd78e433db61 45
rlanghbv 0:bd78e433db61 46 IN1=1;
rlanghbv 0:bd78e433db61 47 IN2=0;
rlanghbv 0:bd78e433db61 48 IN3=1;
rlanghbv 0:bd78e433db61 49 IN4=0;
rlanghbv 0:bd78e433db61 50 wait_us(1000);
rlanghbv 0:bd78e433db61 51
rlanghbv 0:bd78e433db61 52 IN1=0;
rlanghbv 0:bd78e433db61 53 IN2=1;
rlanghbv 0:bd78e433db61 54 IN3=1;
rlanghbv 0:bd78e433db61 55 IN4=0;
rlanghbv 0:bd78e433db61 56 wait_us(1000);
rlanghbv 0:bd78e433db61 57
rlanghbv 0:bd78e433db61 58 IN1=0;
rlanghbv 0:bd78e433db61 59 IN2=1;
rlanghbv 0:bd78e433db61 60 IN3=0;
rlanghbv 0:bd78e433db61 61 IN4=1;
rlanghbv 0:bd78e433db61 62 wait_us(1000);
rlanghbv 0:bd78e433db61 63 }
rlanghbv 0:bd78e433db61 64
rlanghbv 0:bd78e433db61 65
rlanghbv 0:bd78e433db61 66 int main()
rlanghbv 0:bd78e433db61 67 {
rlanghbv 0:bd78e433db61 68 while (true) {
rlanghbv 0:bd78e433db61 69 if(SW==1)
rlanghbv 0:bd78e433db61 70 step4Left();
rlanghbv 0:bd78e433db61 71 else
rlanghbv 0:bd78e433db61 72 step4Right();
rlanghbv 0:bd78e433db61 73
rlanghbv 0:bd78e433db61 74 }
rlanghbv 0:bd78e433db61 75 }