with optic sensor

Dependencies:   Stepper mbed PinDetect

Revision:
4:82cd644fef51
Parent:
3:5410ddd83592
Child:
5:1b451520ed5f
--- a/main.cpp	Wed Sep 04 18:57:27 2019 +0000
+++ b/main.cpp	Wed Sep 04 20:21:21 2019 +0000
@@ -5,26 +5,55 @@
 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);
+    
+   }
+}
 
-int main()
-{
-optic.mode(PullDown);
-wait(0.1);
-int steps = 0;
-int slot = 0;
-en = 1; // stepper motor off
-wait(1);
-mot.setSpeed(400); //stepper speed
-mot.setPositionZero(); //set origin for stepper steps 
-while(1)
+/*while(1)
   {
         pc.printf("\n\n\nEnter desired position: ");
         pc.scanf("%d",&slot); 
         
-        en = 0; //turns on stepper driver
-        mot.goesTo(slot*1000); // move to absolute slot*500 step position
-        while(!mot.stopped()); // while motor is turning...do line below
-        steps = mot.getPosition(); //read in absolute step postition
+        new_optic = optic;
+        while (slot!=positionnum){
+        
+        if (slot>positionnum){
+        en = 0;
+        mot.setSpeed(500);
+        mot.rotate(1);
+        }
+        
+        
         //while(optic == 0)
         //{
         //wait(1);
@@ -50,4 +79,5 @@
         //pc.printf("\nNot in Position", steps);
         //}
     }
-}
+}*/
+