making vague hints at something takes time to process and is incredibly frustrating and time consuming to figure out..
/*
This module runs all physical electronic outputs.
-Pump cylces on every 2 minutes for 30 seconds before shutdown
connected to Digital Pin 0
-LED lights will remain on for a period full 24 hours for
the vegitative phase connected to Digital Pin 3 and 4
-LED lights will need to transition to a X hour day/night
cycle and enable additional blue LED strips connected to
Digital Pin 5
*/
//counter variables
int timer = 0;
int clockSecond = 0;
int clockMinute = 0;
int clockHour = 0;
String cycleSelect;
int cycleWeek = 0;
String lightSelect;
int bluelight =0;
int counterCycle = 1; //pump cycle optimizing variable
int lightSwitchOnOff = 0; //used to avoid reswitching.
//Digital pin assignments and initialization
int lightGrowPrimaryRed = 10; //use digital pin 10 for primary red light
int lightGrowBlue = 11; //use digitial pin 11 for pumping switch
int lightGrowRed = 5; //use digital pin 4 for grow light swtich. these strings of red lights are only on during the vegitative phase
int lightFlowerBlue = 4; //use digital pin 5 for blue light switch
int lightPruning = 6; // use digital pin 7 for blue light pruning function
int waterPump = 7; //use ditital pin 6 for water pump switch
int fanIngress = 8; // use digital pin 8 for ingress fan control
int fanEgress = 9; // use digital pin 9 for egress fan control
const byte switchSLT = 18; //use digital pin 18 to control changing lighting phases from vegitative to flowering and back
const byte switchGrowPhase = 19; // use digital pin 19 to enable/disable Blue Light Pruning aparatis. initial configuration is off
const byte switchFanControl = 20; // use digital pin 20 to enable disable fan control. initial configuration is off
const byte switchMasterPower = 21; //use digital pin 21 to constrol master power on/off for whole system
//Interrupt variable
volatile byte stateFan = 0; //variable to evaluate to enable fans
volatile byte stateGrowPhase = 0; //variable to evaluate which grow phase to put the lighting array in
volatile byte stateSLT = 0; //variable to enable/disable SLT array
volatile byte statePower = 0; // variable control over all electronic functions pointing to a holding function
void setup() {
Serial.begin(9600);
Serial.println("--Start Serial Monitor SEND_RCVE --:");
// pinmode setup for
pinMode(lightGrowBlue, OUTPUT);
pinMode (lightGrowRed, OUTPUT);
pinMode (lightFlowerBlue, OUTPUT);
pinMode (lightGrowPrimaryRed, OUTPUT);
pinMode (waterPump, OUTPUT);
pinMode (fanIngress, OUTPUT);
pinMode (fanEgress, OUTPUT);
pinMode (switchGrowPhase, INPUT);
pinMode (switchSLT, INPUT);
pinMode (switchFanControl, INPUT);
pinMode (switchMasterPower, INPUT);
pinMode(lightPruning, OUTPUT);
digitalWrite(lightPruning,LOW); //turn SLT array off by default
pinMode(switchSLT, INPUT);
//enable interrupts
attachInterrupt(digitalPinToInterrupt(switchGrowPhase), growPhase, RISING);
attachInterrupt(digitalPinToInterrupt(switchSLT), SLTArray, RISING);
attachInterrupt(digitalPinToInterrupt(switchFanControl), fanControl, RISING);
attachInterrupt(digitalPinToInterrupt(switchMasterPower), powerControl, RISING);
//enable primary lighting
digitalWrite(lightGrowPrimaryRed, HIGH);
digitalWrite(lightGrowBlue, HIGH);
/*Fans enabled from initiation of code. Version 3 code allows for disabling/enabling the fans. However,
* they are not independently controled due to wiring constraints in the hardware
*/
digitalWrite(fanIngress, HIGH);
digitalWrite(fanEgress, HIGH);
Serial.print("--End of initialization--");
}
void loop() {
/*
Aeroponics lighting and pump timer code
clock timer works off miliseconds and converts to second, minutes, hours, days, weeks.
this information is then used by the functions vegCycle and flowerCycle to count down to
4 weeks and transition to the flowering cycle, turning the lights off for 6 hours as well
as enabling additional blue spectrum lighting during the day cycle. The pumpCycle function
controls switching the pump on every 2 minutes and then delaying for a period of time before
switching the pump off again and resuming the application.
*/
//check power state variable to disable/enable electronics
switch(statePower){
case '0':
powerOff();
break;
case '1':
powerOn();
break;
}
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 == 60) {
clockHour++;
clockMinute = 0;
}
Serial.print(clockMinute % 2), Serial.println("");
Serial.print("clockSecond = " ), Serial.print(clockSecond), Serial.println("");
Serial.print("ClockMinute = " ), Serial.print(clockMinute), Serial.println("");
Serial.print("Timer = " ), Serial.print(timer), Serial.println("");
//Select day/night cycle pattern
switch (stateGrowPhase) {
case 0:
vegCycle();
break;
case 1:
flowerCycle();
break;
}
//Call pump function
pumpCycle();
}
/*all function calls below this point
*/
void growPhase(){
stateGrowPhase=!stateGrowPhase;
}
void SLTArray(){
stateSLT=!stateSLT;
}
void fanControl(){
stateFan=!stateFan;
}
void powerControl(){
statePower=!statePower;
}
void pumpCycle() {
// Nutrient Pump Cycle Function
int pumpTime = 0;
pumpTime = clockMinute % 2 ;
Serial.print("pumptime variable ="), Serial.print(pumpTime), Serial.println("");
switch (counterCycle){
case 1: //evaluate if the pump should be turned on and passed to the next case or leave disabled
if (pumpTime == 0 && clockSecond == 0) {
digitalWrite(waterPump, HIGH), Serial.print("Nutrient pump is active"), Serial.println("");
counterCycle++;
}
break;
case 2: //determine if pump has been enabled for 30 seconds
if (pumpTime == 0 && clockSecond ==30) {
counterCycle++;
}
break;
case 3: //determine if pump has been enabled for 30 seconds and disables the pump. resets counterCycle if the time has elapsed
if (pumpTime == 0 && clockSecond == 31) {
digitalWrite(waterPump, LOW), Serial.print("Nutrient pump is inactive"), Serial.println("");
counterCycle =1;
}
break;
}
}
void vegCycle() {
// This function defines the always on Day lighting schedule for the vegitating period
switch (lightSwitchOnOff){
case '0':
digitalWrite(lightGrowBlue, HIGH);
digitalWrite(lightGrowRed, HIGH);
digitalWrite(lightGrowPrimaryRed, HIGH);
if (stateGrowPhase == LOW){
lightSwitchOnOff = 1;
}
case '1':
break;
}
Serial.print("Grow Lights are on"), Serial.println("");
}
void flowerCycle() {
//This function controls the lighting for the day/night cycle for the flowering period
//evaluate clockHour with a boolean expression and use in switch
char cycleLight[9] ;
int cycleInt =0;
char var1[3] ={clockHour};
char var2[3] = {clockMinute};
char var3[3] = {timer};
cycleLight = String.concat(var1 + var2 + var3);
cycleInt = cycleLight.toInt();
switch (cycleInt) {
case 00:
digitalWrite(lightGrowBlue, HIGH);
digitalWrite(lightGrowRed, HIGH);
Serial.print("Grow Lights are on. Flowering Cycle"), Serial.println("");
break;
case 170:
digitalWrite(lightGrowBlue, LOW);
digitalWrite(lightGrowRed, LOW);
Serial.print("Grow lights are off. Flowering Cycle"), Serial.println("");
break;
}
}
void powerOff(){
}
void powerOn(){
}