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
- Committer:
- rschimpf78
- Date:
- 2019-09-04
- Revision:
- 5:1b451520ed5f
- Parent:
- 4:82cd644fef51
- Child:
- 6:7cd69300073f
File content as of revision 5:1b451520ed5f:
#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(){
en = 1;
int count = 0;
int old_optic=0;
int new_optic;
optic.mode(PullDown);
wait(0.01);
int slot = 0;
while(1) {
mot.stop();
en = 1;
pc.printf("\n\n\nEnter desired position: ");
pc.scanf("%d",&slot);
while (slot>count){
en = 0;
wait(.001);
mot.setSpeed(300);
wait(.001);
mot.rotate(1);
new_optic = optic;
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;
}
while (slot<count){
en = 0;
wait(.001);
mot.setSpeed(300);
wait(.001);
mot.rotate(0);
new_optic = optic;
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;
}
}
}