#include <LiquidCrystal.h>
enum State
{
Idle,
};
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; // pin 3 of LCD should be connected to GND
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
const int relay1 = 6; // VCC Pin attached to Digital Pin 13, Glycol Pump
const int relay2 = 7; // VCC Pin attached to Digital Pin 12, Water Pump
const int relay3 = 8; // VCC Pin attached to Digital Pin 11, Glycol Intake Solenoid Valve
const int relay4 = 9; // VCC Pin attached to Digital Pin 10, Water Intake Solenoid Valve
const int relay5 = 10; // VCC Pin attached to Digital Pin 9, Glycol Output Solenoid Valve
const int relay6 = 23; // VCC Pin attached to Digital Pin 8, Water Output Solenoid Valve
const int relay7 = 25; // VCC Pin attached to Digital Pin 7, Electric Motor Agitator
const int relay8 = 27; //VCC Pin attached to Digital Pin 6, Mixed Output Solenoid Valve
const int momentary_switch = 52; // pushbutton connected to pin 1 of aurdino board
const int latchingSwitchInputPin = 52;
const int latchingSwitchOutputPin = 3; // Arduino pin connected to relay's pin
const int LED = 51;
const int Glycol_max_sensor = 0; //Pushbutton
const int Glycol_min_sensor = 1; //Pushbutton
const int Water_max_sensor = 14; //Pushbutton
const int Water_min_sensor = 15; //Pushbutton
int counter;
int switchState = LOW; // Variables to store switch states
int lastSwitchState = LOW; // Variables to store switch states
int latchingSwitchState = LOW; // Variables to store switch states
int Glycol_max_sensor_state = HIGH ;
int Glycol_min_sensor_state = HIGH ;
int Water_max_sensor_state = HIGH ;
int Water_min_sensor_state = HIGH ;
// Initialize current state
State currentState = Idle;
void startup();
void Intake_Valve();
void Output_Valve();
void Electric_Motor();
void Mix_Output_Solenoid_Valve();
void setup()
{
lcd.begin(16, 2);
// you can now interact with the LCD, e.g.:
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
pinMode(relay4, OUTPUT);
pinMode(relay5, OUTPUT);
pinMode(relay6, OUTPUT);
pinMode(relay7, OUTPUT);
pinMode(relay8, OUTPUT);
pinMode(momentary_switch, INPUT); // set arduino pin to input mode
pinMode(latchingSwitchInputPin, INPUT);
pinMode(latchingSwitchOutputPin, OUTPUT);
pinMode(LED, OUTPUT); // set arduino pin to input mode
pinMode(Glycol_max_sensor, INPUT_PULLUP);
pinMode(Glycol_min_sensor, INPUT_PULLUP);
pinMode(Water_max_sensor, INPUT_PULLUP);
pinMode(Water_min_sensor, INPUT_PULLUP);
Serial.begin(115200);
}
void loop()
{
power_on();
// Read the state of the momentary switch
switchState = digitalRead(momentary_switch);
// Check for a rising edge (transition from LOW to HIGH) on the momentary switch
if (switchState == HIGH && lastSwitchState == LOW) {
// Toggle the state of the latching switch
latchingSwitchState = !latchingSwitchState;
delay(1000);
digitalWrite(relay1, latchingSwitchState);
digitalWrite(relay2, latchingSwitchState);
digitalWrite(LED, latchingSwitchState);
Serial.println("Toggle Latching Switch");
}
// Update the last switch state
lastSwitchState = switchState;
Serial.println("\n");
switch (counter)
{
case 0: {
int Glycol_max_sensor_state = digitalRead(Glycol_max_sensor);
int Glycol_min_sensor_state = digitalRead(Glycol_min_sensor);
int Water_max_sensor_state = digitalRead(Water_max_sensor);
int Water_min_sensor_state = digitalRead(Water_min_sensor);
lcd.print("Starting UP");
delay(1000);
lcd.clear();
lcd.print("Would you like");
lcd.setCursor(0, 1);
lcd.print("to proceed?");
lcd.clear();
if(switchState == HIGH)
{
if (Glycol_min_sensor_state == HIGH && Water_min_sensor_state == HIGH)
{
startup();
}
counter = 1;
millis();
}
}
/*case 1: { Intake_Valve();
counter = 2;
millis();
break;}
case 2: { Output_Valve();
counter = 3;
millis();
break;}
case 3: { Electric_Motor();
counter = 4;
millis();
break;}
case 4: { Mix_Output_Solenoid_Valve();
counter = 0;
millis();
break;}*/
}
}
void power_on()
{
digitalWrite(relay1, LOW);
digitalWrite(relay2, LOW);
digitalWrite(relay3, LOW);
digitalWrite(relay4, LOW);
digitalWrite(relay5, LOW);
digitalWrite(relay6, LOW);
digitalWrite(relay7, LOW);
digitalWrite(relay8, LOW);
digitalWrite(LED, LOW);
//buttonState = LOW;
latchingSwitchState= LOW;
}
void startup()
{
}