Remote inc coolant nozzle control program

Dependencies:   mbed reScale USBDevice

Dependents:   Nozzle_inputs Nozzle_display

Revision:
2:79c03ac27b72
Parent:
0:09419d572e90
Child:
4:fa0af3a8e089
diff -r 09419d572e90 -r 79c03ac27b72 main.cpp
--- a/main.cpp	Sun Jan 06 18:28:18 2019 +0000
+++ b/main.cpp	Fri Feb 08 20:51:59 2019 +0000
@@ -1,184 +1,191 @@
  #include "mbed.h"
-#include "Adafruit_ST7735.h"
-#include "RotaryEncoder.h"
+
 #include "reScale.h"
-#include "Ee24xx08.h"
+
+
+//Serial pc(USBTX, USBRX);
 
 
-// DISPLAY INIT:
+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.
 
-#define BLACK    0x0000
-#define BLUE     0x001F
-#define RED      0xF800
-#define GREEN    0x07E0
-#define CYAN     0x07FF
-#define MAGENTA  0xF81F
-#define YELLOW   0xFFE0 
-#define WHITE    0xFFFF
+ PwmOut myServo(P1_13); //display board
 
-//const int addrW = 0xA2; //1010 0010 write word block B0
-//const int addrR = 0xA2; //1010 0011 read word block B0
-
-long currentSpot = 0;
-
+//char tens = '0';
+//char ones = '1';
 
-DigitalOut myled(LED1);
-//DigitalOut out(D2);
+ int Tens = 0;
+ int Ones = 0;   
+ 
+ int currentNozzle = 0;          
 
-//I2C i2c(P0_5, P0_4);
-Serial ser(USBTX,USBRX);
-I2C iic(P0_5, P0_4);
-
-Ee24xx08 eeprom(&iic);
+int index = 0;               // for parsing serial
 
-Adafruit_ST7735 tft(D11, D12, D13, D10, D7, D9); // MOSI, MISO, SCLK, SSEL, TFT_DC, TFT_RST
+int n1Pos = 0;
 
-
-RotaryEncoder knob1(D2, D3, -50, 0, 0);
+  int servo1Pos = 0;
 
-reScale servo1Scale(-45,0,750,1800); //19850 is 1.0v from voltage divider at 10k.
+DigitalOut dir(P0_15);
+DigitalOut servo2(P2_2);
 
-//SDFileSystem sd(P1_20, P1_21, P1_22, P1_23, "sd"); // the pinout on the mbed Cool Components workshop board
-
-
-PwmOut myServo(D4);
 
 int main() {
-  //  out =1;
-  
+
+
 
-  
-  
-  
-    
-      tft.initR(INITR_GREENTAB);   // initialize a ST7735S chip, black tab
-      
-        tft.setRotation(3);
-      
-        tft.fillScreen(BLACK);
-  tft.setCursor(30,120);
-  tft.setTextColor(WHITE);
-  tft.setTextWrap(true);
-  tft.printf("AccuBlast v0");
-  
-  int mode=1; // 0= manual, 1=auto
-  int lastMode=0; // placeholder for changing display.
-  
-  int toolNo = 12;
-  int lastToolNo = 99; 
-  
-  int n1Pos = 0;
-  int lastN1Pos = 150;
-  
-  int servo1Pos = 0;
+//pc.printf("HELLO WORLD\n");
+
+
+
+      uint8_t c = 0; // for 485 link
   
-    myServo.period_ms(20);
-   // myServo.pulsewidth_us(MID); //NB in microseconds
-   
-   
-   /*
-   char data[2];
-data[0] = 0x01;
-data[1] = 0x01;
-   
+    while(1) {
+
+while (device.readable())
+            {
+               // c = device.getc();
+               // if(c =='1'){
+               // servo1=1;  
+               // }
+               
 
- char cmd[3];
-        cmd[0] = 0x01;
-        cmd[1] = 0x03;
-        i2c.start();
-        i2c.write(addrW, cmd, 2);
-        cmd[0] = 0x00;
-        cmd[1] = 0x00;
-        i2c.write(addrW, cmd, 2);
-        i2c.stop();
-        i2c.start();
-        //i2c.write(addrR);
-        i2c.read(addrR, data, 2);
-       */ 
-     
-       char str[4] = "-45";
-       char str2[12] = "0";
-       char str3[4] = "3";
-    
-
-    eeprom.write(01,str,4);
-    wait(1);
-    eeprom.write(05,str3,4);
-    wait(1);
-    
-    
-    eeprom.read(01,str2,4);
-   // ser.printf("%s\r\n",str);
-      
+                
+               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;
+                             
+                            }
+                            
+                        }
+                
 
-  tft.setCursor(30,110);
-  tft.setTextColor(WHITE);
-  tft.setTextWrap(true);
-   tft.printf("%s\r\n",str2);
-
-int T1 = int(str2[4]);
-
-  tft.setCursor(30,80);
-  tft.setTextColor(WHITE);
-  tft.setTextWrap(true);
-        tft.printf("%d", T1);
-    
-    while(1) {
-        
- n1Pos = knob1.getVal();
- 
-servo1Pos = servo1Scale.from(knob1.getVal());
-
-myServo.pulsewidth_us(servo1Pos);
+                        
+                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);
 
- if (mode != lastMode) {
-        if (mode==1){
-        tft.fillRect(2, 2, 30, 25, WHITE);      
-        tft.setCursor(8, 4);
-        tft.setTextColor(BLACK);
-        tft.setTextSize(3);
-        tft.printf("A");
-        lastMode = mode;
-        }
-        
-        if (mode == 0){
-        tft.fillRect(2, 2, 40,25, WHITE);      
-        tft.setCursor(4, 4);
-        tft.setTextColor(BLACK);
-        tft.setTextSize(3);
-        tft.printf("M");
-        lastMode=mode;
-        }
-        }
-    
- if (toolNo != lastToolNo){
-        tft.fillRect(103, 2, 55,25, WHITE);      
-        tft.setCursor(105, 4);
-        tft.setTextColor(BLACK);
-        tft.setTextSize(3);
-        tft.printf("T");
-        tft.setCursor(118, 4);
-        tft.printf("%d", toolNo);
-        lastToolNo = toolNo;
-        }
-       
-    
-   if (n1Pos != lastN1Pos){     
-        tft.setCursor(80, 100);
-        tft.setTextColor(BLACK);
-        tft.setTextSize(2);
-        tft.printf("%d", lastN1Pos);
-        tft.setCursor(80, 100);
-        tft.setTextColor(WHITE);
-        tft.setTextSize(2);
-        tft.printf("%d", n1Pos);
-        lastN1Pos = n1Pos;
-        }  
-    
-    
-}
-
+                       myServo.pulsewidth_us(servo1Pos);              
+                         
+                index=0;
+ 
+                
+}                 
 }
 
 
 
+
+}
+}
\ No newline at end of file