Hello,
I am working on a system that uses a number of solenoids in a specified pattern to sample water. There are 7 sampling solenoids X1, X2... X7 and 4 other solenoids A,B,C,D that control the flow of water in the system. For sampling, I need to code the following pattern: X1 opens, B and D close, A closes, C opens, X1 closes, C closes, A opens, B and D open. I wish to set the time this entire process takes to be about 5 seconds and then continue the same for X2, X3.... X7. I'm having a hard time figuring out how to set the time before moving on to the next sampling solenoid. The delay function doesn't work and I'm not sure how to use the millis() function. Here is what I have so far: Thanks in advance!
int sol_B = 22;
int sol_C = 4;
int sol_D = 3;
int sol_A = 12;
long previousMillis = 0;
long interval = 3000;
void setup() {
for(int solX_Pin = 5; solX_Pin < 12; solX_Pin++)
{
pinMode(solX_Pin, OUTPUT);
}pinMode(sol_A, OUTPUT);
pinMode(sol_B, OUTPUT);
pinMode(sol_D, OUTPUT);
pinMode(sol_C, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
unsigned long currentMillis = millis();
digitalWrite(sol_A, HIGH);
digitalWrite(sol_B, HIGH);
digitalWrite(sol_D, HIGH);
delay(5000);
//sampling
for(int solX_Pin = 5; solX_Pin < 12 ; solX_Pin++){
//X opens
if(currentMillis - previousMillis > interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
digitalWrite(solX_Pin, HIGH);
//B and D close
digitalWrite(sol_B, LOW);
digitalWrite(sol_D, LOW);
//A closes
digitalWrite(sol_A, LOW);
//C opens
digitalWrite(sol_C, HIGH);
delay(3000);
//X closes
digitalWrite(solX_Pin, LOW);
//C closes
digitalWrite(sol_C, LOW);
//A opens
digitalWrite(sol_A, HIGH);
//B and D open
digitalWrite(sol_B, HIGH);
digitalWrite(sol_D, HIGH);
}
}
}