Remote inc coolant nozzle control program
Dependencies: mbed reScale USBDevice
Dependents: Nozzle_inputs Nozzle_display
Diff: main.cpp
- Revision:
- 20:8aebc19d9d1d
- Parent:
- 8:6bb07a893f53
- Child:
- 21:db507362ca7a
diff -r 6bb07a893f53 -r 8aebc19d9d1d main.cpp --- a/main.cpp Tue Feb 19 05:56:53 2019 +0000 +++ b/main.cpp Wed Apr 10 20:25:04 2019 +0000 @@ -31,9 +31,12 @@ //char tens = '0'; //char ones = '1'; +int Hundreds = 0; int Tens = 0; int Ones = 0; + int twitch = 0; + int currentNozzle = 0; int index = 0; // for parsing serial @@ -84,6 +87,9 @@ uint8_t c = 0; // for 485 link while(1) { + + + //************************************ Interrupt response ********************** @@ -155,8 +161,9 @@ */ -//********************************** Display serial *************************** +//********************************** Display serial OLD *************************** +/* while (display.readable()) { @@ -294,6 +301,198 @@ } } +*/ + + +//********************** Display code NEW with W ********************************** + + while (display.readable()) { + + c = display.getc(); + + if (c == 'N') { + + index = 1; + + } + + if (c == 'W') { // wiggle setting + index = 5; + } + if (index == 5) { + c = display.getc(); + if (c == '0') { + twitch = 0; + index = 0; + } + if (c == '1') { + twitch = 1; + } + if (c == '2') { + twitch = 2; + index = 0; + } + if (c == '3') { + twitch = 3; + index = 0; + } + } + + + + + if (index == 1) { //Display is sending -90>+90 and adding 190 for N1 so would send 100 to 280 for -90 to +90 + c = display.getc(); + if (c == '1') { // N1 + currentNozzle = 1; + Hundreds = 0; + index = 3; + + + } else if (c == '2') { //N2 + currentNozzle = 1; + Hundreds = 1; + index = 3; + } + + if (c == '3') { //N2 // Display adding 390 for N2 so 300 to 480 would be -90 to +90 + currentNozzle = 2; + Hundreds = 0; + index = 3; + } + + if (c == '4') { //N2 + currentNozzle = 2; + Hundreds = 1; + index = 3; + } + + + } + + + + if (index == 3) { + + c = display.getc(); + + if (c=='0') { + Tens = 0; + index = 4; + + } + + else if (c=='1') { + Tens = 1; + index = 4; + + } + + else if (c=='2') { + Tens = 2; + index = 4; + + } + + else if (c=='3') { + Tens = 3; + index = 4; + + } + + else if (c=='4') { + Tens = 4; + index = 4; + } + + else if (c=='5') { + Tens = 5; + index = 4; + } + + else if (c=='6') { + Tens = 6; + index = 4; + } + + else if (c=='7') { + Tens = 7; + index = 4; + } + + else if (c=='8') { + Tens = 8; + index = 4; + } + + else if (c=='9') { + Tens = 9; + index = 4; + } + + + } + + if (index == 4) { + + c = display.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; + } + + n1Pos = ((Tens * 10) + Ones); + + if ((n1Pos == 45) && (currentNozzle==1)) { +// servo2=1; + } + + servo1Pos = servo1Scale.from(n1Pos); + + servo1.pulsewidth_us(servo1Pos); + + index=0; + } + } + + + //********************************* Inputs serial *******************************