Remote inc coolant nozzle control program
Dependencies: mbed reScale USBDevice
Dependents: Nozzle_inputs Nozzle_display
main.cpp
- Committer:
- BETZtechnik
- Date:
- 2019-02-08
- Revision:
- 2:79c03ac27b72
- Parent:
- 0:09419d572e90
- Child:
- 4:fa0af3a8e089
File content as of revision 2:79c03ac27b72:
#include "mbed.h" #include "reScale.h" //Serial pc(USBTX, USBRX); Serial device(P0_14, P0_13, 9600); // 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 //char tens = '0'; //char ones = '1'; int Tens = 0; int Ones = 0; int currentNozzle = 0; int index = 0; // for parsing serial int n1Pos = 0; int servo1Pos = 0; DigitalOut dir(P0_15); DigitalOut servo2(P2_2); int main() { //pc.printf("HELLO WORLD\n"); uint8_t c = 0; // for 485 link while(1) { while (device.readable()) { // c = device.getc(); // if(c =='1'){ // servo1=1; // } c = device.getc(); if (c == 'N'){ index = 1; } if (index == 1){ c = device.getc(); if (c == '1'){ // N1 currentNozzle = 1; index = 3; } else if (c == '2'){ //N2 currentNozzle = 2; index = 3; } } if (index == 3){ c = device.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; } } if (index == 4){ c = device.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; } n1Pos = ((Tens * 10) + Ones); if ((n1Pos == 45) && (currentNozzle==1)){ servo2=1; } servo1Pos = servo1Scale.from(n1Pos); myServo.pulsewidth_us(servo1Pos); index=0; } } } }