ytsuboi kappa

Dependencies:   mbed

Fork of A4988_sample by Yoshihiro TSUBOI

Committer:
kkkkkkk
Date:
Tue Aug 29 13:07:03 2017 +0000
Revision:
2:90df823dbf59
Parent:
1:3f5ad896f93b
abc

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ytsuboi 0:b9c1a7c906f5 1 // simple A4988 sample
ytsuboi 0:b9c1a7c906f5 2 // jumper reset and sleep together
ytsuboi 0:b9c1a7c906f5 3 // connect VDD to mbed VOUT
ytsuboi 0:b9c1a7c906f5 4 // connect GND to mbed GND
ytsuboi 0:b9c1a7c906f5 5 // connect 1A and 1B to stepper coil 1 (GREEN and BLACK wire)
ytsuboi 0:b9c1a7c906f5 6 // connect 2A and 2B to stepper coil 2 (BLUE and RED wire)
ytsuboi 0:b9c1a7c906f5 7 // connect VMOT to power source (to AC adapter)
ytsuboi 0:b9c1a7c906f5 8 // connect GRD to power source (to AC adapter)
ytsuboi 0:b9c1a7c906f5 9 // connect STEP to mbed p22
ytsuboi 0:b9c1a7c906f5 10 // connect DIR to mbed p21
ytsuboi 0:b9c1a7c906f5 11
ytsuboi 0:b9c1a7c906f5 12 #include "mbed.h"
ytsuboi 0:b9c1a7c906f5 13
kkkkkkk 1:3f5ad896f93b 14 DigitalOut A4988STEP(D4);
kkkkkkk 1:3f5ad896f93b 15 DigitalOut A4988DIR(D5);
ytsuboi 0:b9c1a7c906f5 16 int a=0;
ytsuboi 0:b9c1a7c906f5 17
ytsuboi 0:b9c1a7c906f5 18 int main() {
ytsuboi 0:b9c1a7c906f5 19 A4988DIR = 0;
ytsuboi 0:b9c1a7c906f5 20 A4988STEP = 0;
ytsuboi 0:b9c1a7c906f5 21 while(1) {
ytsuboi 0:b9c1a7c906f5 22 if (a < 200) //sweep 200 step in dir 1
ytsuboi 0:b9c1a7c906f5 23 {
ytsuboi 0:b9c1a7c906f5 24 a++;
ytsuboi 0:b9c1a7c906f5 25 A4988STEP = 1;
ytsuboi 0:b9c1a7c906f5 26 wait(0.008);
ytsuboi 0:b9c1a7c906f5 27 A4988STEP = 0;
ytsuboi 0:b9c1a7c906f5 28 wait(0.008);
ytsuboi 0:b9c1a7c906f5 29 }
ytsuboi 0:b9c1a7c906f5 30 else
ytsuboi 0:b9c1a7c906f5 31 {
ytsuboi 0:b9c1a7c906f5 32 A4988DIR = 1;
ytsuboi 0:b9c1a7c906f5 33 a++;
ytsuboi 0:b9c1a7c906f5 34 A4988STEP = 1;
ytsuboi 0:b9c1a7c906f5 35 wait(0.008);
ytsuboi 0:b9c1a7c906f5 36 A4988STEP = 0;
ytsuboi 0:b9c1a7c906f5 37 wait(0.008);
ytsuboi 0:b9c1a7c906f5 38
ytsuboi 0:b9c1a7c906f5 39 if (a>400) //sweep 200 in dir 2
ytsuboi 0:b9c1a7c906f5 40 {
ytsuboi 0:b9c1a7c906f5 41 a = 0;
ytsuboi 0:b9c1a7c906f5 42 A4988DIR = 0;
ytsuboi 0:b9c1a7c906f5 43 }
ytsuboi 0:b9c1a7c906f5 44 }
ytsuboi 0:b9c1a7c906f5 45 }
ytsuboi 0:b9c1a7c906f5 46 }