with optic sensor
Dependencies: Stepper mbed PinDetect
main.cpp
- Committer:
- rschimpf78
- Date:
- 2019-09-04
- Revision:
- 4:82cd644fef51
- Parent:
- 3:5410ddd83592
- Child:
- 5:1b451520ed5f
File content as of revision 4:82cd644fef51:
#include "mbed.h" #include "Stepper.h" #include "string" DigitalIn optic(D5); Stepper mot(D3,D2); //(PUL+,DIR+) DigitalOut en(D4); Serial pc(USBTX, USBRX); DigitalOut myled(LED1); DigitalOut myled2(LED2); DigitalOut myled3(LED3); DigitalOut myled4(LED4); int main(){ int count = 0; int old_optic=0; int new_optic; optic.mode(PullDown); wait(0.01); //int positionnum = 0; //int slot = 0; //en = 1; // stepper motor off while(1) { new_optic = optic; //if (new_optic!= old_optic){ pc.printf("\new optic:%ld",new_optic); wait(.5); if ((new_optic==1) && (old_optic==0)){ myled4 = count & 0x01; myled3 = (count & 0x02)>>1; myled2 = (count & 0x04)>>2; myled = (count & 0x08)>>3; count++; pc.printf("\ncount:%ld",count); } old_optic = new_optic; wait(.5); pc.printf("\ncount:%ld",count); } } /*while(1) { pc.printf("\n\n\nEnter desired position: "); pc.scanf("%d",&slot); new_optic = optic; while (slot!=positionnum){ if (slot>positionnum){ en = 0; mot.setSpeed(500); mot.rotate(1); } //while(optic == 0) //{ //wait(1); //mot.goesTo(steps+25); //go to absolute step position //while(!mot.stopped()); //steps = mot.getPosition(); //pc.printf("\nNot in Position", steps); //} pc.printf("\nIn Position"); en = 1; //disable the motor and driver //if (tickcount<steps) //{ //mot.goesTo(steps+25); //while(!mot.stopped()); //steps = mot.getPosition(); //pc.printf("\nNot in Position", steps); //} //if (tickcount>steps) //{ //mot.goesTo(steps-25); //while(!mot.stopped()); //steps = mot.getPosition(); //pc.printf("\nNot in Position", steps); //} } }*/