Remote inc coolant nozzle control program

Dependencies:   mbed reScale USBDevice

Dependents:   Nozzle_inputs Nozzle_display

Revision:
5:18c6ff1370d0
Parent:
4:fa0af3a8e089
Child:
8:6bb07a893f53
--- a/main.cpp	Sat Feb 09 23:46:05 2019 +0000
+++ b/main.cpp	Mon Feb 11 00:47:47 2019 +0000
@@ -5,12 +5,25 @@
 
 //Serial pc(USBTX, USBRX);
 
+//InterruptIn aux1(P0_7, PullUp); // index pulse
 
-Serial device(P0_14, P0_13, 9600);  // RS 485  TX RX?
+DigitalIn aux1(P0_7);
+DigitalIn cw(P1_24); 
+DigitalIn ccw(P2_7);
+
+int cwRequested = 0;
+int ccwRequested = 0;
+
+int aux1State = 0;
+
+
+DigitalOut dir(P0_15);
+
+Serial device(P0_14, P0_13, 19200);  // RS 485  TX RX?
 
 reScale servo1Scale(45,0,750,1800); //19850 is 1.0v from voltage divider at 10k.
 
- PwmOut myServo(P1_13); //display board
+ PwmOut servo1(P1_13); //display board
 
 //char tens = '0';
 //char ones = '1';
@@ -26,15 +39,40 @@
 
   int servo1Pos = 0;
 
-DigitalOut dir(P0_15);
+
 DigitalOut servo2(P2_2);
 
 
+void triggered()
+{
+    servo2 = 1;
+    
+    if (cw == 0){
+        cwRequested = 1;
+        }
+        
+        else if (ccw == 0){
+            ccwRequested = 1;
+            }
+        
+}            
+    
+
+
+
+
 int main() {
     
+cw.mode(PullUp);
+ccw.mode(PullUp);
+aux1.mode(PullUp);
 
 
-//pc.printf("HELLO WORLD\n");
+//aux1.rise(&triggered);
+
+
+
+servo2 = 0;
 
 
 
@@ -42,15 +80,81 @@
   
     while(1) {
         
+//************************************  Interrupt response **********************       
+        
+        
+        if (aux1 == 1 && aux1State == 0)
+        {
+           
+           if (cw == 0)
+           {
+//servo2 = 1;
+dir= 1;
+//wait(0.001);
+device.printf("M");
+wait(0.05);
+device.printf("+");
+wait(0.001);
+dir=0;
+aux1State = 1;
+//wait(.001);
+}
+
+if (ccw == 0)
+{
+dir= 1;
+//wait(0.01);
+device.printf("M");
+wait(0.05);
+device.printf("-");
+wait(0.001);
+dir=0;
+aux1State = 1;
+//wait(.001);
+}
+}
+
+if (aux1 == 0 && aux1State == 1)
+{
+aux1State = 0;
+//wait(0.1);
+}          
             
+        /*
+if (cwRequested == 1)
+{
+dir= 1;
+//wait(0.001);
+device.printf("M");
+wait(0.01);
+device.printf("+");
+wait(0.001);
+dir=0;
+cwRequested = 0;
+//wait(.001);
+}
+
+
+else if (ccwRequested == 1)
+{
+dir= 1;
+//wait(0.01);
+device.printf("M");
+wait(0.01);
+device.printf("-");
+wait(0.001);
+dir=0;
+ccwRequested = 0;
+//wait(.001);
+}
+   */ 
+    
+        
+//********************************** Serial listening ***************************       
 
 while (device.readable())
-            {
-               // c = device.getc();
-               // if(c =='1'){
-               // servo1=1;  
-               // }
-               
+{
+             
 
                 
                c = device.getc();
@@ -170,28 +274,24 @@
                                      
                                 
                                      
-                       n1Pos = ((Tens * 10) + Ones);
+n1Pos = ((Tens * 10) + Ones);
                        
-                       if ((n1Pos == 45) && (currentNozzle==1)){
-                              servo2=1;
-                            }
+if ((n1Pos == 45) && (currentNozzle==1)){
+// servo2=1;
+}
                        
-                       servo1Pos = servo1Scale.from(n1Pos);
+servo1Pos = servo1Scale.from(n1Pos);
 
-                       myServo.pulsewidth_us(servo1Pos);              
+servo1.pulsewidth_us(servo1Pos);              
                          
-                index=0;
+index=0;
  
                 
 }                 
 }
 
 
-dir= 1;
-    wait(0.1);
-device.printf("M-");
-//device.printf("0");
-dir=0;
+
 
 
 }