ytsuboi kappa

Dependencies:   mbed

Fork of A4988_sample by Yoshihiro TSUBOI

main.cpp

Committer:
kkkkkkk
Date:
2017-08-29
Revision:
2:90df823dbf59
Parent:
1:3f5ad896f93b

File content as of revision 2:90df823dbf59:

// 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(D4);
DigitalOut A4988DIR(D5);
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;
         }
        }
    }
}