Remote inc coolant nozzle control program

Dependencies:   mbed reScale USBDevice

Dependents:   Nozzle_inputs Nozzle_display

main.cpp

Committer:
BETZtechnik
Date:
2019-01-06
Revision:
0:09419d572e90
Child:
1:e8452b75301e
Child:
2:79c03ac27b72

File content as of revision 0:09419d572e90:

 #include "mbed.h"
#include "Adafruit_ST7735.h"
#include "RotaryEncoder.h"
#include "reScale.h"
#include "Ee24xx08.h"


// DISPLAY INIT:

#define BLACK    0x0000
#define BLUE     0x001F
#define RED      0xF800
#define GREEN    0x07E0
#define CYAN     0x07FF
#define MAGENTA  0xF81F
#define YELLOW   0xFFE0 
#define WHITE    0xFFFF

//const int addrW = 0xA2; //1010 0010 write word block B0
//const int addrR = 0xA2; //1010 0011 read word block B0

long currentSpot = 0;


DigitalOut myled(LED1);
//DigitalOut out(D2);

//I2C i2c(P0_5, P0_4);
Serial ser(USBTX,USBRX);
I2C iic(P0_5, P0_4);

Ee24xx08 eeprom(&iic);

Adafruit_ST7735 tft(D11, D12, D13, D10, D7, D9); // MOSI, MISO, SCLK, SSEL, TFT_DC, TFT_RST


RotaryEncoder knob1(D2, D3, -50, 0, 0);

reScale servo1Scale(-45,0,750,1800); //19850 is 1.0v from voltage divider at 10k.

//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;
  
    myServo.period_ms(20);
   // myServo.pulsewidth_us(MID); //NB in microseconds
   
   
   /*
   char data[2];
data[0] = 0x01;
data[1] = 0x01;
   

 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);
      

  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 (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;
        }  
    
    
}

}