Remote inc coolant nozzle control program
Dependencies: mbed reScale USBDevice
Dependents: Nozzle_inputs Nozzle_display
Diff: main.cpp
- Revision:
- 8:6bb07a893f53
- Parent:
- 5:18c6ff1370d0
- Child:
- 18:40499bfc9ab2
- Child:
- 20:8aebc19d9d1d
--- a/main.cpp Mon Feb 11 00:47:47 2019 +0000 +++ b/main.cpp Tue Feb 19 05:56:53 2019 +0000 @@ -19,7 +19,10 @@ DigitalOut dir(P0_15); -Serial device(P0_14, P0_13, 19200); // RS 485 TX RX? +Serial display(P0_14, P0_13, 19200); // RS 485 TX RX? +Serial inputs(P1_23,P0_20, 9600); //rs232 TX RX + + reScale servo1Scale(45,0,750,1800); //19850 is 1.0v from voltage divider at 10k. @@ -42,7 +45,7 @@ DigitalOut servo2(P2_2); - +/* void triggered() { servo2 = 1; @@ -57,7 +60,7 @@ } - +*/ @@ -68,6 +71,8 @@ aux1.mode(PullUp); + + //aux1.rise(&triggered); @@ -81,32 +86,32 @@ while(1) { //************************************ Interrupt response ********************** - + - if (aux1 == 1 && aux1State == 0) + if (aux1 == 0 && aux1State == 0) { - if (cw == 0) + if (cw == 1) { //servo2 = 1; dir= 1; //wait(0.001); -device.printf("M"); +display.printf("M"); wait(0.05); -device.printf("+"); +display.printf("-"); wait(0.001); dir=0; aux1State = 1; //wait(.001); } -if (ccw == 0) +if (ccw == 1) { dir= 1; //wait(0.01); -device.printf("M"); +display.printf("M"); wait(0.05); -device.printf("-"); +display.printf("+"); wait(0.001); dir=0; aux1State = 1; @@ -114,7 +119,7 @@ } } -if (aux1 == 0 && aux1State == 1) +if (aux1 == 1 && aux1State == 1) { aux1State = 0; //wait(0.1); @@ -125,9 +130,9 @@ { dir= 1; //wait(0.001); -device.printf("M"); +display.printf("M"); wait(0.01); -device.printf("+"); +display.printf("+"); wait(0.001); dir=0; cwRequested = 0; @@ -139,9 +144,9 @@ { dir= 1; //wait(0.01); -device.printf("M"); +display.printf("M"); wait(0.01); -device.printf("-"); +display.printf("-"); wait(0.001); dir=0; ccwRequested = 0; @@ -150,14 +155,14 @@ */ -//********************************** Serial listening *************************** +//********************************** Display serial *************************** -while (device.readable()) +while (display.readable()) { - c = device.getc(); + c = display.getc(); if (c == 'N'){ @@ -166,7 +171,7 @@ } if (index == 1){ - c = device.getc(); + c = display.getc(); if (c == '1'){ // N1 currentNozzle = 1; index = 3; @@ -185,7 +190,7 @@ if (index == 3){ - c = device.getc(); + c = display.getc(); if (c=='0'){ Tens = 0; @@ -221,7 +226,7 @@ if (index == 4){ - c = device.getc(); + c = display.getc(); if (c=='0'){ Ones = 0; @@ -291,6 +296,145 @@ } +//********************************* Inputs serial ******************************* + + +while (inputs.readable()) +{ + + + c = inputs.getc(); + + if (c == 'T'){ + + index = 1; + servo2=1; + } + + + if (index == 1){ + c = inputs.getc(); + + + if (c=='0'){ + Tens = 0; + servo2=1; + } + + else if (c=='1'){ + Tens = 1; + + + } + + else if (c=='2'){ + Tens = 2; + + } + + else if (c=='3'){ + Tens = 3; + + } + + else if (c=='4'){ + Tens = 4; + } + + else if (c=='5'){ + Tens = 5; + } + + else if (c=='6'){ + Tens = 6; + } + + else if (c=='7'){ + Tens = 7; + } + + else if (c=='8'){ + Tens = 8; + } + + else if (c=='9'){ + Tens = 9; + } + + else if (c=='0'){ + Tens = 0; + } + index = 2; + } + + + if (index == 2){ + c = inputs.getc(); + if (c=='0'){ + Ones = 0; + + } + + else if (c=='1'){ + Ones = 1; + + + } + + else if (c=='2'){ + Ones = 2; + + } + + else if (c=='3'){ + Ones = 3; + + } + + else if (c=='4'){ + Ones = 4; + } + + else if (c=='5'){ + Ones = 5; + } + + else if (c=='6'){ + Ones = 6; + } + + else if (c=='7'){ + Ones = 7; + } + + else if (c=='8'){ + Ones = 8; + } + + else if (c=='9'){ + Ones = 9; + } + + else if (c=='0'){ + Ones = 0; + } + int tempToolNo = (Tens*10)+100+Ones; + dir=1; + display.printf("T"); + wait(0.05); + display.printf("%d", tempToolNo); + wait(0.001); + dir=0; + index = 0; + tempToolNo=0; + + } + + + } + + +// *****************************************************************************