I'm attempting to cycle through ball valves that are 3 wire, 2 return leads and 1 load. there is a built in cut off in the hardware to cut power once it has cycled open or closed, but I still need to tell my circuit to shut off the connection. I'm using an array of clock times to determine when these action should occur, but i'm unable to test against them in a switch statement. firstly, is it possible to evaluate a variable in a switch statement or will I need to use an if/then. the switch in question is on line 87.
/*
* This code controls the nutrient solution delivery, allowing delivery of nutrient solutions to
* individual root chambers, alternating between individual root chambers and diverting flow
* back to the nutrient resevuor to stir the solution
*/
// Ball valve array variables
int valveOpen[] = {4,6,8}; // even elements represent open
int valveClose[] = {5,7,9}; // odd elements represent close
int valveActionOn[] = {100,250,550,251};
int valveActionOff[] = {151,300,1,301};
// Pump varriable
int nutPump = 10;
//Array Modifiers
int arrayMod =0;
//counter variables **reset all counter variables to 0 for upload to production controller
int timer = 0;
int clockSecond = 0;
int clockMinute = 0;
String cycleLight;
int cycleInt;
//variable variables
int valveSwitchOn =0;
int valveSwitchOff =0;
void setup() {
//initialize ball valve array as outputs
for(int i; i<3; i++)
{
pinMode(valveOpen[i], OUTPUT);
pinMode(valveClose[i], OUTPUT);
}
//Initialize pump
pinMode (nutPump, OUTPUT);
digitalWrite(valveOpen[4], HIGH);
// delay 100;
digitalWrite(nutPump, HIGH);
//initialize variable variables
int varValveOpen;
int varValveClose;
int varValveAction;
//time string conversion
String cycleTime;
//begin serial transmition
Serial.begin(9600);
Serial.println("--Start Serial Monitor SEND_RCVE --:");
}
void loop() {
//
//Timer code to count clock time
timer++;
if (timer == 20) { //timer must be changed and tested for accuracy if additional code is added
clockSecond++;
timer = 0;
}
if (clockSecond == 60) {
clockMinute++;
clockSecond = 0;
}
if (clockMinute == 5) {
clockMinute = 0;
}
cycleLight = (String(timer)+String(clockSecond)+String(clockMinute));
cycleInt = cycleLight.toInt();
Serial.print("clockSecond = " ), Serial.print(clockSecond), Serial.println("");
Serial.print("ClockMinute = " ), Serial.print(clockMinute), Serial.println("");
Serial.print("Timer = " ), Serial.print(timer), Serial.println("");
Serial.print("Cycle number = "), Serial.print(cycleInt), Serial.println("");
valveSwitchOn = valveActionOn[arrayMod];
valveSwitchOff = valveActionOff[arrayMod];
switch(cycleInt){
case valveSwitchOn:
transition();
break;
case valveSwitchOff:
PowerOff();
break;
}
}
void Transition(){
digitalWrite(valveOpen[arrayMod], HIGH);
digitalWrite(valveClose[arrayMod], HIGH;
}
void PowerOff(){
digitalWrite(valveOpen[arrayMod], LOW);
digitalWrite(valveClose[arrayMod], LOW);
arrayMod++;
switch (arrayMod){
case 3:
arrayMod=0;
break;
}
}