step motor test of CORE-1000
Dependencies: mbed
main.cpp@1:0677e9d605d3, 2019-01-09 (annotated)
- Committer:
- odb
- Date:
- Wed Jan 09 08:01:57 2019 +0000
- Revision:
- 1:0677e9d605d3
- Parent:
- 0:9354648a14ed
Step motor test of CORE-1000
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
odb | 0:9354648a14ed | 1 | // 28BYJ-48 stepper motor example |
odb | 0:9354648a14ed | 2 | // showing how to control a unipolar stepper motor by mbed digital output ports. |
odb | 0:9354648a14ed | 3 | // Tested on the Nucleo F103RB Board |
odb | 0:9354648a14ed | 4 | // Based on http://www.geeetech.com/wiki/index.php/Stepper_Motor_5V_4-Phase_5-Wire_%26_ULN2003_Driver_Board_for_Arduino |
odb | 0:9354648a14ed | 5 | // Using the ULN2003A Driver. |
odb | 0:9354648a14ed | 6 | |
odb | 0:9354648a14ed | 7 | #include "mbed.h" |
odb | 0:9354648a14ed | 8 | |
odb | 1:0677e9d605d3 | 9 | BusOut motor_out(PB_1, PB_15, PB_14, PB_13); // blue - pink - yellow - orange rev2.0 |
odb | 0:9354648a14ed | 10 | int step = 0; |
odb | 0:9354648a14ed | 11 | int dir = 1; // direction |
odb | 0:9354648a14ed | 12 | |
odb | 0:9354648a14ed | 13 | int main() |
odb | 0:9354648a14ed | 14 | { |
odb | 0:9354648a14ed | 15 | while(1) |
odb | 0:9354648a14ed | 16 | { |
odb | 0:9354648a14ed | 17 | switch(step) |
odb | 0:9354648a14ed | 18 | { |
odb | 0:9354648a14ed | 19 | case 0: motor_out = 0x1; break; // 0001 |
odb | 0:9354648a14ed | 20 | case 1: motor_out = 0x3; break; // 0011 |
odb | 0:9354648a14ed | 21 | case 2: motor_out = 0x2; break; // 0010 |
odb | 0:9354648a14ed | 22 | case 3: motor_out = 0x6; break; // 0110 |
odb | 0:9354648a14ed | 23 | case 4: motor_out = 0x4; break; // 0100 |
odb | 0:9354648a14ed | 24 | case 5: motor_out = 0xC; break; // 1100 |
odb | 0:9354648a14ed | 25 | case 6: motor_out = 0x8; break; // 1000 |
odb | 0:9354648a14ed | 26 | case 7: motor_out = 0x9; break; // 1001 |
odb | 0:9354648a14ed | 27 | |
odb | 0:9354648a14ed | 28 | default: motor_out = 0x0; break; // 0000 |
odb | 0:9354648a14ed | 29 | } |
odb | 0:9354648a14ed | 30 | |
odb | 0:9354648a14ed | 31 | if(dir) step++; else step--; |
odb | 0:9354648a14ed | 32 | if(step>7)step=0; |
odb | 0:9354648a14ed | 33 | if(step<0)step=7; |
odb | 0:9354648a14ed | 34 | wait(0.015); // speed |
odb | 0:9354648a14ed | 35 | } |
odb | 0:9354648a14ed | 36 | } |
odb | 0:9354648a14ed | 37 |