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.
Dependencies: Stepper mbed PinDetect
main.cpp
00001 #include "mbed.h" 00002 #include "Stepper.h" 00003 #include "string" 00004 DigitalIn optic(D5); 00005 Stepper mot(D3,D2); //(PUL+,DIR+) 00006 DigitalOut en(D4); 00007 Serial pc(USBTX, USBRX); 00008 00009 int main() 00010 { 00011 optic.mode(PullDown); 00012 wait(0.1); 00013 int steps = 0; 00014 int slot = 0; 00015 en = 1; // stepper motor off 00016 wait(1); 00017 mot.setSpeed(400); //stepper speed 00018 mot.setPositionZero(); //set origin for stepper steps 00019 while(1) 00020 { 00021 pc.printf("\n\n\nEnter desired position: "); 00022 pc.scanf("%d",&slot); 00023 00024 en = 0; //turns on stepper driver 00025 mot.goesTo(slot*1000); // move to absolute slot*500 step position 00026 while(!mot.stopped()); // while motor is turning...do line below 00027 steps = mot.getPosition(); //read in absolute step postition 00028 pc.printf("\nIn Position"); 00029 en = 1; //disable the motor and driver 00030 } 00031 }
Generated on Sat Jul 16 2022 22:39:27 by
1.7.2