Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of stepper by
a4988.cpp
00001 #include "a4988.h" 00002 #include "mbed.h" 00003 extern int stepok; 00004 Stepper::Stepper(PinName _en, PinName _stepPin, PinName _direction):en(_en), 00005 stepPin(_stepPin), 00006 direction(_direction) 00007 { 00008 00009 } 00010 void Stepper::step(int dir, long long int frequency ,volatile long long int _remain) 00011 { 00012 //fun = &Stepper::step_control; 00013 if (dir == 1) { 00014 direction = 0; 00015 } else if (dir == 0) { 00016 direction = 1; 00017 } 00018 remain = _remain; 00019 step_ticker.attach(this, &Stepper::step_control,0.5/frequency); 00020 } 00021 00022 void Stepper::enable() 00023 { 00024 en = 0; 00025 } 00026 00027 void Stepper::disable() 00028 { 00029 en = 1; 00030 } 00031 00032 void Stepper::step_control() 00033 { 00034 if(remain == 0) 00035 { 00036 stepok = 1; 00037 return ; 00038 } 00039 if(remain < 0 ) 00040 { 00041 if(stepPin){ 00042 stepPin = 0; //STEP 1->0 00043 }else{ 00044 stepPin = 1; //STEP 0->1 00045 } 00046 } 00047 00048 if(stepPin){ 00049 stepPin = 0; //STEP 1->0 00050 remain--; 00051 }else{ 00052 stepPin = 1; //STEP 0->1 00053 } 00054 }
Generated on Tue Jul 19 2022 10:05:46 by
