void setup()
{
Serial.begin(9600); //Baud Rate//
Serial.print(17,BYTE); //Backlight For LCD//
pinMode(1,OUTPUT); //LCD Screen//
pinMode(3, OUTPUT); //Conductivity Sensor//
pinMode(8,OUTPUT); //Solenoid Valve//
pinMode(9,OUTPUT); //Solenoid Valve/
pinMode(11,OUTPUT); // top middle // BLUE = everything in check (between UCL and LCL on both heat and salinity)
pinMode(6,OUTPUT); // bottom middle // small green = deadtime
pinMode(12,OUTPUT); // top left // green = above salt Upper Control Limit
pinMode(10,OUTPUT); // bottom left // yellow = Below salt Lower Control Limit
pinMode(7,OUTPUT); // top right // green = above temp UCL
pinMode(5, OUTPUT); // bottom right // yellow = below temp LCL
pinMode(0, INPUT); // Momentary Switch //
Serial.print(12, BYTE); // Clear Screen//
Serial.print(129,BYTE);
Serial.print("LCL");
Serial.print(136,BYTE);
Serial.print("SP");
Serial.print(143,BYTE);
Serial.print("UCL");
Serial.print(188,BYTE);
Serial.print("SALTY");
Serial.print(194,BYTE);
Serial.print("CURRENT");
Serial.print(203,BYTE);
Serial.print("DI");
}
void loop()
{
double P_SETPOINT = .0008;
int A_SETPOINT;
int deadtime=8000;
A_SETPOINT = 972.07*pow(.0008,.0926);
int UCL = A_SETPOINT+6;
double P_UCL = 3*pow(10,-32)*pow(UCL,10.503)+.01;
int LCL = A_SETPOINT-6;
double P_LCL = 3*pow(10,-32)*pow(LCL,10.503)+.01;
digitalWrite(3,HIGH);
delay(500);
int Analog;
Analog = analogRead(0);
digitalWrite(3,LOW); //Conductivity Sensor
double Sal;
Sal = 3*pow(10,-32)*pow(Analog,10.503);
Serial.print(175,BYTE);
Serial.print(Sal*100,3);
if (Analog > UCL)
{
digitalWrite(12,HIGH);
digitalWrite(6,HIGH);
delay(deadtime);
digitalWrite(6,LOW);
delay(100);
digitalWrite(3,HIGH);
delay(500);
int Analog;
Analog = analogRead(0);
digitalWrite(3,LOW); //Conductivity Sensor
Serial.print(175,BYTE);
Serial.print(Sal*100,3);
Serial.print(" ");
double Sal;
double topen;
double C2;
double Madd;
Sal = 3*pow(10,-32)*pow(Analog,10.503);
C2 = Sal-((Sal-(P_SETPOINT))*(.8));
Madd = (84.6*(Sal-C2))/(.85*Sal);
topen = (Madd/7.528)*1000;
int Button = digitalRead(0);
if(Button==LOW){
Serial.print(17,BYTE);
delay(300);
Serial.print(18,BYTE);
delay(300);
Serial.print(17,BYTE);
delay(300);
Serial.print(18,BYTE);
delay(300);
}
if (Button==HIGH) {
digitalWrite(8,HIGH);
delay(topen);
digitalWrite(8,LOW);
delay(50);
}
digitalWrite(6,HIGH);
delay(deadtime);
digitalWrite(6,LOW);
delay(100);
digitalWrite(12,LOW);
}
if (Analog < LCL)
{
digitalWrite(10,HIGH);
digitalWrite(6,HIGH);
delay(deadtime);
digitalWrite(6,LOW);
delay(100);
digitalWrite(3,HIGH);
delay(500);
int Analog;
Analog = analogRead(0);
digitalWrite(3,LOW); //Conductivity Sensor
double topen;
double Sal;
double C2;
double Madd;
Sal = 3*pow(10,-32)*pow(Analog,10.503);
C2 = Sal+((P_SETPOINT-Sal)*.8);
Madd = (84.6*(C2-Sal))/(.85*(.0015-Sal));
topen = (Madd/7.528)*1000;
int Button=digitalRead(0);
if(Button==LOW){
Serial.print(18,BYTE);
delay(300);
Serial.print(17,BYTE);
delay(300);
}
if (Button==HIGH){
Serial.print(17,BYTE);
delay(300);
digitalWrite(9,HIGH);
delay(topen);
digitalWrite(9,LOW);
delay(100);
}
digitalWrite(6,HIGH);
delay(deadtime);
digitalWrite(6,LOW);
delay(100);
}
if (UCL>Analog>LCL)
{
digitalWrite(8,LOW);
digitalWrite(9,LOW);
digitalWrite(11,HIGH);
}
}
Thanks guys