below is some code ive started, so KeithRB I should just nest some if loops to take care of the conditions?...how do I jump out once the process has started?
thanks again for the help
/*
Keg Washer
Uses mega2560 with 16 channel relay board to actuate ball valves to appropriate plumbing sources
*/
int valves[] = {
2, 3, 4, 5, 6, 7, 8, 9, 10
}; // an array of pin numbers to which LEDs are attached
int pinCount = 9; // the number of pins (i.e. the length of the array)
int drain = 0;
int air = 1;
int hotH20 = 2;
int caustic = 3;
int acid = 4;
int sany = 5;
int co2 = 6;
int causticDrain = 7;
int acidDrain = 8;
char state = 0;
void setup() {
// the array elements are numbered from 0 to (pinCount - 1).
// use a for loop to initialize each pin as an output:
Serial.begin(9600);
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
pinMode(valves[thisPin], OUTPUT); // sets as output
digitalWrite(valves[thisPin], HIGH); // turns relays off
}
}
//void(* resetFunc) (void) = 0;//declare reset function at address 0
void loop() {
// begin the keg washer cycle
while (Serial.available() > 0) {
// get incoming byte:
state = Serial.read();
// resetFunc(); //call reset
}
while (state == '1') {
digitalWrite(valves[drain], LOW); // open drain
Serial.println("open drain");
digitalWrite(valves[air], LOW); // purge air
Serial.println("purge air");
delay(10000);
digitalWrite(valves[air], HIGH); // air off
Serial.println("purge air off");
digitalWrite(valves[hotH20],LOW);// open hot rinse
Serial.println("open hot rinse");
delay(10000);
digitalWrite(valves[hotH20], HIGH); // close hot rinse
Serial.println("close hot rinse");
digitalWrite(valves[air], LOW); // open air purge
Serial.println("purge air");
delay(10000);
digitalWrite(valves[air], HIGH); // close air purge
Serial.println("purge air off");
digitalWrite(valves[caustic], LOW); // open caustic supply
Serial.println("start caustic");
digitalWrite(valves[causticDrain], LOW); // open caustic return
Serial.println("open caustic return");
digitalWrite(valves[drain], HIGH); // close drain
Serial.println("close drain");
delay(30000);
digitalWrite(valves[caustic], HIGH);
Serial.println("close caustic");
digitalWrite(valves[air], LOW);
Serial.println("purge air");
delay(10000);
digitalWrite(valves[air], HIGH);
Serial.println("purge air off");
digitalWrite(valves[causticDrain], HIGH);
Serial.println("close caustic return");
digitalWrite(valves[drain], LOW);
Serial.println("open drain");
delay(5000);
digitalWrite(valves[hotH20], LOW);
Serial.println("open hot rinse");
delay(10000);
digitalWrite(valves[hotH20], HIGH);
digitalWrite(valves[air], LOW);
delay(5000);
digitalWrite(valves[air], HIGH);
digitalWrite(valves[acid], LOW); // open caustic supply
digitalWrite(valves[acidDrain], LOW); // open caustic return
digitalWrite(valves[drain], HIGH); // close drain
delay(30000);
digitalWrite(valves[acid], HIGH);
digitalWrite(valves[air], LOW);
delay(10000);
digitalWrite(valves[air], HIGH);
digitalWrite(valves[acidDrain], HIGH);
digitalWrite(valves[drain], LOW);
delay(5000);
digitalWrite(valves[hotH20], LOW);
delay(10000);
digitalWrite(valves[hotH20], HIGH);
digitalWrite(valves[air], LOW);
delay(5000);
digitalWrite(valves[air], HIGH);
digitalWrite(valves[sany], LOW);
delay(15000);
digitalWrite(valves[sany], HIGH);
digitalWrite(valves[co2], LOW);
delay(5000);
digitalWrite(valves[drain], HIGH);
delay(10000);
state = 48;
}
while(state== '0'){
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
digitalWrite(valves[thisPin], HIGH);
Serial.println("all valves closed");
}
while (Serial.available() > 0) {
// get incoming byte:
state = Serial.read();
// resetFunc(); //call reset
}
}
}
void serialEvent() {
while (Serial.available() > 0) {
// get incoming byte:
state = Serial.read();
// resetFunc(); //call reset
}
}