![](/media/cache/profiles/697e382cfd25b07a3e62275d3ee132b3.jpg.50x50_q85.png)
A simple sample to try to control stepper with Allegro A4988 stepper driver
Diff: main.cpp
- Revision:
- 0:b9c1a7c906f5
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Mar 22 15:41:45 2014 +0000 @@ -0,0 +1,47 @@ +// simple A4988 sample +// jumper reset and sleep together +// connect VDD to mbed VOUT +// connect GND to mbed GND +// connect 1A and 1B to stepper coil 1 (GREEN and BLACK wire) +// connect 2A and 2B to stepper coil 2 (BLUE and RED wire) +// connect VMOT to power source (to AC adapter) +// connect GRD to power source (to AC adapter) +// connect STEP to mbed p22 +// connect DIR to mbed p21 + +#include "mbed.h" + +DigitalOut A4988STEP(p22); +DigitalOut A4988DIR(p21); +int a=0; + +int main() { + A4988DIR = 0; + A4988STEP = 0; + + while(1) { + if (a < 200) //sweep 200 step in dir 1 + { + a++; + A4988STEP = 1; + wait(0.008); + A4988STEP = 0; + wait(0.008); + } + else + { + A4988DIR = 1; + a++; + A4988STEP = 1; + wait(0.008); + A4988STEP = 0; + wait(0.008); + + if (a>400) //sweep 200 in dir 2 + { + a = 0; + A4988DIR = 0; + } + } + } +}