rename PIN variables to a more equal naming schema

This commit is contained in:
Marcus 2024-05-01 00:55:55 +02:00
parent bd4ee79ed7
commit ee5be296ec

View file

@ -139,10 +139,10 @@ byte LighthoursBloom = 12;
byte SunriseHour = 7; byte SunriseHour = 7;
// SunriseHour - contains to which minute of SunriseHour the growlight turns on // SunriseHour - contains to which minute of SunriseHour the growlight turns on
byte SunriseMinute = 0; byte SunriseMinute = 0;
// PINledPWM - contains the PWM value for dimming the grow light // PinLEDPWM - contains the PWM value for dimming the grow light
// default is 255 to ensure it is just on for the case UseLEDrelais is true // default is 255 to ensure it is just on for the case UseLEDrelais is true
byte PINledPWM = 255; byte PinLEDPWM = 255;
byte PINfanPWM = 255; byte PinFANPWM = 255;
// fade in and out sunrise and sunset? // fade in and out sunrise and sunset?
bool SunFade; bool SunFade;
@ -336,15 +336,15 @@ function convertDateToEpoch(src, dst) {
*/ */
// D0 is HIGH at boot, no PWM // D0 is HIGH at boot, no PWM
const uint8_t PINpump = D0; const uint8_t PinPUMP = D0;
// If D3 is pulled to LOW, boot fails // If D3 is pulled to LOW, boot fails
const uint8_t PINdht = D3; const uint8_t PINdht = D3;
// D4 is HIGH at boot, boot fail if pulled to LOW // D4 is HIGH at boot, boot fail if pulled to LOW
// During Start Screen you can pull D4 to LOW to wipe saved data in EEPROM // During Start Screen you can pull D4 to LOW to wipe saved data in EEPROM
// DO NOT PULL D4 DOWN AT WHEN POWERING ON !!! BOOT WILL FAIL // DO NOT PULL D4 DOWN AT WHEN POWERING ON !!! BOOT WILL FAIL
const uint8_t PIN_WIPE = D4; const uint8_t PIN_WIPE = D4;
const uint8_t PINfan = D5; const uint8_t PinFAN = D5;
const uint8_t PINled = D6; // const uint8_t PinLED = D6; //
const uint8_t PINwaterlevel = D7; const uint8_t PINwaterlevel = D7;
const uint8_t PINsoilmoisture = D8; const uint8_t PINsoilmoisture = D8;
const uint8_t PINanalog = A0; const uint8_t PINanalog = A0;
@ -675,10 +675,10 @@ bool loadEEPROM() {
* *
* -- afterwards added, need to sort -- * -- afterwards added, need to sort --
* *
* 213 PINledPWM * 213 PinLEDPWM
* 214 TemperatureSensor_Type * 214 TemperatureSensor_Type
* 215 UseFANrelais * 215 UseFANrelais
* 216 PINfanPWM * 216 PinFANPWM
* 217 SunFade * 217 SunFade
* 218 SunFadeDuration * 218 SunFadeDuration
* *
@ -769,9 +769,9 @@ bool loadEEPROM() {
// size is 1 byte // size is 1 byte
EEPROM.get(212, DayOfGrow); EEPROM.get(212, DayOfGrow);
// size is 1 byte // size is 1 byte
EEPROM.get(213, PINledPWM); EEPROM.get(213, PinLEDPWM);
// size is 1 byte // size is 1 byte
EEPROM.get(216, PINfanPWM); EEPROM.get(216, PinFANPWM);
EEPROM.get(217, SunFade); EEPROM.get(217, SunFade);
EEPROM.get(218, SunFadeDuration); EEPROM.get(218, SunFadeDuration);
@ -828,10 +828,10 @@ bool loadEEPROM() {
Serial.println(SunriseMinute); Serial.println(SunriseMinute);
Serial.print("DayOfGrow: "); Serial.print("DayOfGrow: ");
Serial.println(DayOfGrow); Serial.println(DayOfGrow);
Serial.print("PINledPWM: "); Serial.print("PinLEDPWM: ");
Serial.println(PINledPWM); Serial.println(PinLEDPWM);
Serial.print("PINfanPWM: "); Serial.print("PinFANPWM: ");
Serial.println(PINfanPWM); Serial.println(PinFANPWM);
Serial.print("SunFade: "); Serial.print("SunFade: ");
Serial.println(SunFade); Serial.println(SunFade);
Serial.print("SunFadeDuration: "); Serial.print("SunFadeDuration: ");
@ -938,7 +938,7 @@ void setOutput(byte Output, byte OutputState) {
switch(Output) { switch(Output) {
case 1: case 1:
OutputPin = PINled; OutputPin = PinLED;
if(UseLEDrelais == true) { if(UseLEDrelais == true) {
UseRelais = true; UseRelais = true;
} else { } else {
@ -946,7 +946,7 @@ void setOutput(byte Output, byte OutputState) {
} }
break; break;
case 2: case 2:
OutputPin = PINfan; OutputPin = PinFAN;
if(UseFANrelais == true) { if(UseFANrelais == true) {
UseRelais = true; UseRelais = true;
} else { } else {
@ -955,7 +955,7 @@ void setOutput(byte Output, byte OutputState) {
break; break;
// PUMP Pin (D0) does not support PWM, so we do not need to care about // PUMP Pin (D0) does not support PWM, so we do not need to care about
case 3: case 3:
OutputPin = PINpump; OutputPin = PinPUMP;
break; break;
} }
@ -968,7 +968,7 @@ void setOutput(byte Output, byte OutputState) {
//~ Serial.print("UseRelais: "); //~ Serial.print("UseRelais: ");
//~ Serial.println(UseRelais); //~ Serial.println(UseRelais);
if( (UseRelais == true) || (OutputPin == PINpump) ) { if( (UseRelais == true) || (OutputPin == PinPUMP) ) {
digitalWrite(OutputPin, OutputState); digitalWrite(OutputPin, OutputState);
} else { } else {
analogWrite(OutputPin, OutputState); analogWrite(OutputPin, OutputState);
@ -976,9 +976,9 @@ void setOutput(byte Output, byte OutputState) {
} }
void setGrowLED() { void controlLED() {
byte lightHours; byte lightHours;
byte PINledPWM_tmp; byte PinLEDPWM_tmp;
unsigned int secondsSunrise = (SunriseHour * 60 * 60) + (SunriseMinute * 60); unsigned int secondsSunrise = (SunriseHour * 60 * 60) + (SunriseMinute * 60);
unsigned int secondsToday = (timeClient.getHours() * 60 * 60) + (timeClient.getMinutes() * 60) + timeClient.getSeconds(); unsigned int secondsToday = (timeClient.getHours() * 60 * 60) + (timeClient.getMinutes() * 60) + timeClient.getSeconds();
@ -998,22 +998,22 @@ void setGrowLED() {
// in the first n minutes of lighting (SunFadeDuration), we want // in the first n minutes of lighting (SunFadeDuration), we want
// to raise the light slowly to prevent stress from the plant // to raise the light slowly to prevent stress from the plant
// convert progress sunrise to PWM value // convert progress sunrise to PWM value
PINledPWM_tmp = (SunFadeDuration * 60 - ((secondsSunrise + SunFadeDuration * 60) - secondsToday)) * PINledPWM / (SunFadeDuration * 60); PinLEDPWM_tmp = (SunFadeDuration * 60 - ((secondsSunrise + SunFadeDuration * 60) - secondsToday)) * PinLEDPWM / (SunFadeDuration * 60);
setOutput(1, PINledPWM_tmp); setOutput(1, PinLEDPWM_tmp);
//Serial.print("sunrise PWM; "); //Serial.print("sunrise PWM; ");
//Serial.println(PINledPWM_tmp); //Serial.println(PinLEDPWM_tmp);
} else if( (SunFade == true) && (UseLEDrelais == false) && (secondsToday >= ((secondsSunrise + lightHours * 60 * 60) - SunFadeDuration * 60) ) ) { } else if( (SunFade == true) && (UseLEDrelais == false) && (secondsToday >= ((secondsSunrise + lightHours * 60 * 60) - SunFadeDuration * 60) ) ) {
// calculate progress sunset to PWM value // calculate progress sunset to PWM value
PINledPWM_tmp = (secondsSunrise + (lightHours * 60 * 60) - secondsToday) * PINledPWM / (SunFadeDuration * 60); PinLEDPWM_tmp = (secondsSunrise + (lightHours * 60 * 60) - secondsToday) * PinLEDPWM / (SunFadeDuration * 60);
setOutput(1, PINledPWM_tmp); setOutput(1, PinLEDPWM_tmp);
//Serial.print("sunset PWM: "); //Serial.print("sunset PWM: ");
//Serial.println(PINledPWM_tmp); //Serial.println(PinLEDPWM_tmp);
} else { } else {
//Serial.println("just turn on the light"); //Serial.println("just turn on the light");
// no sunrise or sunset, just keep the LED turned on // no sunrise or sunset, just keep the LED turned on
setOutput(1, PINledPWM); setOutput(1, PinLEDPWM);
} }
} else { } else {
@ -1042,21 +1042,21 @@ void setup() {
EEPROM.begin(512); EEPROM.begin(512);
// setup pins // setup pins
pinMode(PINfan, OUTPUT); pinMode(PinFAN, OUTPUT);
pinMode(PINdht, INPUT); pinMode(PINdht, INPUT);
pinMode(PINwaterlevel, OUTPUT); pinMode(PINwaterlevel, OUTPUT);
pinMode(PINsoilmoisture, OUTPUT); pinMode(PINsoilmoisture, OUTPUT);
pinMode(PINled, OUTPUT); pinMode(PinLED, OUTPUT);
pinMode(PINpump, OUTPUT); pinMode(PinPUMP, OUTPUT);
pinMode(PIN_WIPE, OUTPUT); pinMode(PIN_WIPE, OUTPUT);
// set all OUTPUT to low // set all OUTPUT to low
digitalWrite(PINfan, LOW); digitalWrite(PinFAN, LOW);
digitalWrite(PINwaterlevel, LOW); digitalWrite(PINwaterlevel, LOW);
digitalWrite(PINsoilmoisture, LOW); digitalWrite(PINsoilmoisture, LOW);
digitalWrite(PINled, LOW); digitalWrite(PinLED, LOW);
digitalWrite(PINpump, LOW); digitalWrite(PinPUMP, LOW);
// set PWM frequency lower to avoid annoying noises // set PWM frequency lower to avoid annoying noises
// in combination with 47uF at fan output, 220Hz is kinda sweetspot // in combination with 47uF at fan output, 220Hz is kinda sweetspot
@ -1184,7 +1184,7 @@ void loop() {
// when DayOfGrow is larger then DaysVeg we must be in Bloom // when DayOfGrow is larger then DaysVeg we must be in Bloom
// set the actual state of the Grow LED // set the actual state of the Grow LED
setGrowLED(); controlLED();
// current time gets previous time for new interval // current time gets previous time for new interval
@ -1327,7 +1327,7 @@ String returnHTMLheader(String MenuEntry = "") {
/* /*
* returnSelected(bool) * returnSelected(bool)
* returns char[] "selected" if bool is true * returns char[] "selected" if bool is true
* useful for html forms, to preset a saved value as selected * useful for html forms, to represet a saved value as selected
*/ */
String returnStrSelected(byte savedValue, byte selectId) { String returnStrSelected(byte savedValue, byte selectId) {
String returnStr; String returnStr;
@ -1526,7 +1526,7 @@ void WEBroot() {
} }
body += "<br>"; body += "<br>";
body += "Growlight brightnes: "; body += "Growlight brightnes: ";
body += ((PINledPWM * 100) / 255); body += ((PinLEDPWM * 100) / 255);
body += " %<br>"; body += " %<br>";
body += "<form method='post' action='/switch'>"; body += "<form method='post' action='/switch'>";
body += "MOSFET<select id='output' name='output' required>\n"; body += "MOSFET<select id='output' name='output' required>\n";
@ -1803,14 +1803,14 @@ void WEBgrowSettings() {
body+= "' required><br>\n"; body+= "' required><br>\n";
if(UseLEDrelais == false) { if(UseLEDrelais == false) {
body += "Brightness LED: <input type='range' id='PINledPWM' name='PINledPWM' min='1' max='255' value='"; body += "Brightness LED: <input type='range' id='PinLEDPWM' name='PinLEDPWM' min='1' max='255' value='";
body += PINledPWM; body += PinLEDPWM;
body += "'/><br>\n"; body += "'/><br>\n";
} }
if(UseFANrelais == false) { if(UseFANrelais == false) {
body += "Speed FAN: <input type='range' id='PINfanPWM' name='PINfanPWM' min='1' max='255' value='"; body += "Speed FAN: <input type='range' id='PinFANPWM' name='PinFANPWM' min='1' max='255' value='";
body += PINfanPWM; body += PinFANPWM;
body += "'/><br>\n"; body += "'/><br>\n";
} }
@ -1834,18 +1834,18 @@ void POSTgrowSettings() {
if(UseLEDrelais == true) { if(UseLEDrelais == true) {
// if a relais is used to turn on grow light, we force PWM to max val // if a relais is used to turn on grow light, we force PWM to max val
PINledPWM = 255; PinLEDPWM = 255;
} else { } else {
// otherwise just do PWM // otherwise just do PWM
PINledPWM = webserver.arg("PINledPWM").toInt(); PinLEDPWM = webserver.arg("PinLEDPWM").toInt();
} }
if(UseFANrelais == true) { if(UseFANrelais == true) {
// if a relais is used to turn on grow light, we force PWM to max val // if a relais is used to turn on grow light, we force PWM to max val
PINfanPWM = 255; PinFANPWM = 255;
} else { } else {
// otherwise just do PWM // otherwise just do PWM
PINfanPWM = webserver.arg("PINfanPWM").toInt(); PinFANPWM = webserver.arg("PinFANPWM").toInt();
} }
String GrowName_tmp = webserver.arg("GrowName"); String GrowName_tmp = webserver.arg("GrowName");
@ -1879,9 +1879,9 @@ void POSTgrowSettings() {
// size is 1 byte // size is 1 byte
EEPROM.put(211, SunriseMinute); EEPROM.put(211, SunriseMinute);
// size is 1 byte // size is 1 byte
EEPROM.put(213, PINledPWM); EEPROM.put(213, PinLEDPWM);
// size is 1 byte // size is 1 byte
EEPROM.put(216, PINfanPWM); EEPROM.put(216, PinFANPWM);
EEPROM.put(217, SunFade); EEPROM.put(217, SunFade);
EEPROM.put(218, SunFadeDuration); EEPROM.put(218, SunFadeDuration);
@ -1890,7 +1890,7 @@ void POSTgrowSettings() {
//analogWrite(PINled, PINledPWM); //analogWrite(PinLED, PinLEDPWM);
Serial.println(":: POSTgrowSettings ::"); Serial.println(":: POSTgrowSettings ::");
@ -1910,10 +1910,10 @@ void POSTgrowSettings() {
Serial.println(SunriseHour); Serial.println(SunriseHour);
Serial.print("SunriseMinute: "); Serial.print("SunriseMinute: ");
Serial.println(SunriseMinute); Serial.println(SunriseMinute);
Serial.print("PINledPWM: "); Serial.print("PinLEDPWM: ");
Serial.println(PINledPWM); Serial.println(PinLEDPWM);
Serial.print("PINfanPWM: "); Serial.print("PinFANPWM: ");
Serial.println(PINfanPWM); Serial.println(PinFANPWM);
webserver.sendHeader("Location", String("/growSettings?success"), true); webserver.sendHeader("Location", String("/growSettings?success"), true);
webserver.send(302, "text/plain", "growSettings/save: success!\n"); webserver.send(302, "text/plain", "growSettings/save: success!\n");
@ -1965,20 +1965,20 @@ void POSTsystemSettings() {
Serial.println(":: POSTsystemSettings ::"); Serial.println(":: POSTsystemSettings ::");
// when user uses an relais for LED control, we force here PINledPWM to 255 // when user uses an relais for LED control, we force here PinLEDPWM to 255
// to ensure nothing bad happens // to ensure nothing bad happens
if(UseLEDrelais == true) { if(UseLEDrelais == true) {
PINledPWM = 255; PinLEDPWM = 255;
EEPROM.put(213, PINledPWM); EEPROM.put(213, PinLEDPWM);
EEPROM.commit(); EEPROM.commit();
Serial.println("UseLEDrelais is 1, forcing PINledPWM to max to prevent relais damage"); Serial.println("UseLEDrelais is 1, forcing PinLEDPWM to max to prevent relais damage");
} }
if(UseFANrelais == true) { if(UseFANrelais == true) {
PINfanPWM = 255; PinFANPWM = 255;
EEPROM.put(215, PINfanPWM); EEPROM.put(215, PinFANPWM);
EEPROM.commit(); EEPROM.commit();
Serial.println("UseFANrelais is 1, forcing PINfanPWM to max to prevent relais damage"); Serial.println("UseFANrelais is 1, forcing PinFANPWM to max to prevent relais damage");
} }
Serial.print("configured: "); Serial.print("configured: ");
@ -2077,7 +2077,7 @@ void POSTwifiSettings() {
void POSTsetOutput() { void POSTsetOutput() {
byte OutputState = webserver.arg("state").toInt(); byte OutputState = webserver.arg("state").toInt();
byte OutputNr = webserver.arg("output").toInt(); byte OutputNr = webserver.arg("output").toInt();
//PINledPWM = webserver.arg("PINledPWM").toInt(); //PinLEDPWM = webserver.arg("PinLEDPWM").toInt();
byte OutputPWM = webserver.arg("OutputPWM").toInt(); byte OutputPWM = webserver.arg("OutputPWM").toInt();
Serial.println(":: POSTsetOutput ::"); Serial.println(":: POSTsetOutput ::");
@ -2190,19 +2190,19 @@ void APIgetSensors() {
switch(valWaterlevel) { switch(valWaterlevel) {
case 0: case 0:
digitalWrite(PINled, HIGH); digitalWrite(PinLED, HIGH);
digitalWrite(PINpump, LOW); digitalWrite(PinPUMP, LOW);
digitalWrite(PINfan, LOW); digitalWrite(PinFAN, LOW);
break; break;
case 1: case 1:
digitalWrite(PINled, LOW); digitalWrite(PinLED, LOW);
digitalWrite(PINpump, HIGH); digitalWrite(PinPUMP, HIGH);
digitalWrite(PINfan, LOW); digitalWrite(PinFAN, LOW);
break; break;
case 2: case 2:
digitalWrite(PINled, LOW); digitalWrite(PinLED, LOW);
digitalWrite(PINpump, LOW); digitalWrite(PinPUMP, LOW);
digitalWrite(PINfan, HIGH); digitalWrite(PinFAN, HIGH);
break; break;
} }
@ -2260,15 +2260,15 @@ void APIgetSensors() {
/* if(D6status == true) { /* if(D6status == true) {
digitalWrite(PINled, LOW); digitalWrite(PinLED, LOW);
digitalWrite(PINpump, LOW); digitalWrite(PinPUMP, LOW);
digitalWrite(PINfan, LOW); digitalWrite(PinFAN, LOW);
D6status = false; D6status = false;
Serial.println("D6 is off now"); Serial.println("D6 is off now");
} else { } else {
digitalWrite(PINled, HIGH); digitalWrite(PinLED, HIGH);
digitalWrite(PINpump, HIGH); digitalWrite(PinPUMP, HIGH);
digitalWrite(PINfan, HIGH); digitalWrite(PinFAN, HIGH);
D6status = true; D6status = true;
Serial.println("D6 is ON now"); Serial.println("D6 is ON now");
} }
@ -2277,14 +2277,14 @@ void APIgetSensors() {
/* /*
for(int dutyCycle = 0; dutyCycle < 255; dutyCycle++){ for(int dutyCycle = 0; dutyCycle < 255; dutyCycle++){
// changing the LED brightness with PWM // changing the LED brightness with PWM
analogWrite(PINled, dutyCycle); analogWrite(PinLED, dutyCycle);
delay(1); delay(1);
} }
// decrease the LED brightness // decrease the LED brightness
for(int dutyCycle = 255; dutyCycle > 0; dutyCycle--){ for(int dutyCycle = 255; dutyCycle > 0; dutyCycle--){
// changing the LED brightness with PWM // changing the LED brightness with PWM
analogWrite(PINled, dutyCycle); analogWrite(PinLED, dutyCycle);
delay(1); delay(1);
} }
*/ */