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;
// SunriseHour - contains to which minute of SunriseHour the growlight turns on
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
byte PINledPWM = 255;
byte PINfanPWM = 255;
byte PinLEDPWM = 255;
byte PinFANPWM = 255;
// fade in and out sunrise and sunset?
bool SunFade;
@ -336,15 +336,15 @@ function convertDateToEpoch(src, dst) {
*/
// 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
const uint8_t PINdht = D3;
// 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
// DO NOT PULL D4 DOWN AT WHEN POWERING ON !!! BOOT WILL FAIL
const uint8_t PIN_WIPE = D4;
const uint8_t PINfan = D5;
const uint8_t PINled = D6; //
const uint8_t PinFAN = D5;
const uint8_t PinLED = D6; //
const uint8_t PINwaterlevel = D7;
const uint8_t PINsoilmoisture = D8;
const uint8_t PINanalog = A0;
@ -675,10 +675,10 @@ bool loadEEPROM() {
*
* -- afterwards added, need to sort --
*
* 213 PINledPWM
* 213 PinLEDPWM
* 214 TemperatureSensor_Type
* 215 UseFANrelais
* 216 PINfanPWM
* 216 PinFANPWM
* 217 SunFade
* 218 SunFadeDuration
*
@ -769,9 +769,9 @@ bool loadEEPROM() {
// size is 1 byte
EEPROM.get(212, DayOfGrow);
// size is 1 byte
EEPROM.get(213, PINledPWM);
EEPROM.get(213, PinLEDPWM);
// size is 1 byte
EEPROM.get(216, PINfanPWM);
EEPROM.get(216, PinFANPWM);
EEPROM.get(217, SunFade);
EEPROM.get(218, SunFadeDuration);
@ -828,10 +828,10 @@ bool loadEEPROM() {
Serial.println(SunriseMinute);
Serial.print("DayOfGrow: ");
Serial.println(DayOfGrow);
Serial.print("PINledPWM: ");
Serial.println(PINledPWM);
Serial.print("PINfanPWM: ");
Serial.println(PINfanPWM);
Serial.print("PinLEDPWM: ");
Serial.println(PinLEDPWM);
Serial.print("PinFANPWM: ");
Serial.println(PinFANPWM);
Serial.print("SunFade: ");
Serial.println(SunFade);
Serial.print("SunFadeDuration: ");
@ -938,7 +938,7 @@ void setOutput(byte Output, byte OutputState) {
switch(Output) {
case 1:
OutputPin = PINled;
OutputPin = PinLED;
if(UseLEDrelais == true) {
UseRelais = true;
} else {
@ -946,7 +946,7 @@ void setOutput(byte Output, byte OutputState) {
}
break;
case 2:
OutputPin = PINfan;
OutputPin = PinFAN;
if(UseFANrelais == true) {
UseRelais = true;
} else {
@ -955,7 +955,7 @@ void setOutput(byte Output, byte OutputState) {
break;
// PUMP Pin (D0) does not support PWM, so we do not need to care about
case 3:
OutputPin = PINpump;
OutputPin = PinPUMP;
break;
}
@ -968,7 +968,7 @@ void setOutput(byte Output, byte OutputState) {
//~ Serial.print("UseRelais: ");
//~ Serial.println(UseRelais);
if( (UseRelais == true) || (OutputPin == PINpump) ) {
if( (UseRelais == true) || (OutputPin == PinPUMP) ) {
digitalWrite(OutputPin, OutputState);
} else {
analogWrite(OutputPin, OutputState);
@ -976,9 +976,9 @@ void setOutput(byte Output, byte OutputState) {
}
void setGrowLED() {
void controlLED() {
byte lightHours;
byte PINledPWM_tmp;
byte PinLEDPWM_tmp;
unsigned int secondsSunrise = (SunriseHour * 60 * 60) + (SunriseMinute * 60);
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
// to raise the light slowly to prevent stress from the plant
// convert progress sunrise to PWM value
PINledPWM_tmp = (SunFadeDuration * 60 - ((secondsSunrise + SunFadeDuration * 60) - secondsToday)) * PINledPWM / (SunFadeDuration * 60);
setOutput(1, PINledPWM_tmp);
PinLEDPWM_tmp = (SunFadeDuration * 60 - ((secondsSunrise + SunFadeDuration * 60) - secondsToday)) * PinLEDPWM / (SunFadeDuration * 60);
setOutput(1, PinLEDPWM_tmp);
//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) ) ) {
// calculate progress sunset to PWM value
PINledPWM_tmp = (secondsSunrise + (lightHours * 60 * 60) - secondsToday) * PINledPWM / (SunFadeDuration * 60);
setOutput(1, PINledPWM_tmp);
PinLEDPWM_tmp = (secondsSunrise + (lightHours * 60 * 60) - secondsToday) * PinLEDPWM / (SunFadeDuration * 60);
setOutput(1, PinLEDPWM_tmp);
//Serial.print("sunset PWM: ");
//Serial.println(PINledPWM_tmp);
//Serial.println(PinLEDPWM_tmp);
} else {
//Serial.println("just turn on the light");
// no sunrise or sunset, just keep the LED turned on
setOutput(1, PINledPWM);
setOutput(1, PinLEDPWM);
}
} else {
@ -1042,21 +1042,21 @@ void setup() {
EEPROM.begin(512);
// setup pins
pinMode(PINfan, OUTPUT);
pinMode(PinFAN, OUTPUT);
pinMode(PINdht, INPUT);
pinMode(PINwaterlevel, OUTPUT);
pinMode(PINsoilmoisture, OUTPUT);
pinMode(PINled, OUTPUT);
pinMode(PINpump, OUTPUT);
pinMode(PinLED, OUTPUT);
pinMode(PinPUMP, OUTPUT);
pinMode(PIN_WIPE, OUTPUT);
// set all OUTPUT to low
digitalWrite(PINfan, LOW);
digitalWrite(PinFAN, LOW);
digitalWrite(PINwaterlevel, LOW);
digitalWrite(PINsoilmoisture, LOW);
digitalWrite(PINled, LOW);
digitalWrite(PINpump, LOW);
digitalWrite(PinLED, LOW);
digitalWrite(PinPUMP, LOW);
// set PWM frequency lower to avoid annoying noises
// 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
// set the actual state of the Grow LED
setGrowLED();
controlLED();
// current time gets previous time for new interval
@ -1327,7 +1327,7 @@ String returnHTMLheader(String MenuEntry = "") {
/*
* returnSelected(bool)
* 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 returnStr;
@ -1526,7 +1526,7 @@ void WEBroot() {
}
body += "<br>";
body += "Growlight brightnes: ";
body += ((PINledPWM * 100) / 255);
body += ((PinLEDPWM * 100) / 255);
body += " %<br>";
body += "<form method='post' action='/switch'>";
body += "MOSFET<select id='output' name='output' required>\n";
@ -1803,14 +1803,14 @@ void WEBgrowSettings() {
body+= "' required><br>\n";
if(UseLEDrelais == false) {
body += "Brightness LED: <input type='range' id='PINledPWM' name='PINledPWM' min='1' max='255' value='";
body += PINledPWM;
body += "Brightness LED: <input type='range' id='PinLEDPWM' name='PinLEDPWM' min='1' max='255' value='";
body += PinLEDPWM;
body += "'/><br>\n";
}
if(UseFANrelais == false) {
body += "Speed FAN: <input type='range' id='PINfanPWM' name='PINfanPWM' min='1' max='255' value='";
body += PINfanPWM;
body += "Speed FAN: <input type='range' id='PinFANPWM' name='PinFANPWM' min='1' max='255' value='";
body += PinFANPWM;
body += "'/><br>\n";
}
@ -1834,18 +1834,18 @@ void POSTgrowSettings() {
if(UseLEDrelais == true) {
// if a relais is used to turn on grow light, we force PWM to max val
PINledPWM = 255;
PinLEDPWM = 255;
} else {
// otherwise just do PWM
PINledPWM = webserver.arg("PINledPWM").toInt();
PinLEDPWM = webserver.arg("PinLEDPWM").toInt();
}
if(UseFANrelais == true) {
// if a relais is used to turn on grow light, we force PWM to max val
PINfanPWM = 255;
PinFANPWM = 255;
} else {
// otherwise just do PWM
PINfanPWM = webserver.arg("PINfanPWM").toInt();
PinFANPWM = webserver.arg("PinFANPWM").toInt();
}
String GrowName_tmp = webserver.arg("GrowName");
@ -1879,9 +1879,9 @@ void POSTgrowSettings() {
// size is 1 byte
EEPROM.put(211, SunriseMinute);
// size is 1 byte
EEPROM.put(213, PINledPWM);
EEPROM.put(213, PinLEDPWM);
// size is 1 byte
EEPROM.put(216, PINfanPWM);
EEPROM.put(216, PinFANPWM);
EEPROM.put(217, SunFade);
EEPROM.put(218, SunFadeDuration);
@ -1890,7 +1890,7 @@ void POSTgrowSettings() {
//analogWrite(PINled, PINledPWM);
//analogWrite(PinLED, PinLEDPWM);
Serial.println(":: POSTgrowSettings ::");
@ -1910,10 +1910,10 @@ void POSTgrowSettings() {
Serial.println(SunriseHour);
Serial.print("SunriseMinute: ");
Serial.println(SunriseMinute);
Serial.print("PINledPWM: ");
Serial.println(PINledPWM);
Serial.print("PINfanPWM: ");
Serial.println(PINfanPWM);
Serial.print("PinLEDPWM: ");
Serial.println(PinLEDPWM);
Serial.print("PinFANPWM: ");
Serial.println(PinFANPWM);
webserver.sendHeader("Location", String("/growSettings?success"), true);
webserver.send(302, "text/plain", "growSettings/save: success!\n");
@ -1965,20 +1965,20 @@ void 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
if(UseLEDrelais == true) {
PINledPWM = 255;
EEPROM.put(213, PINledPWM);
PinLEDPWM = 255;
EEPROM.put(213, PinLEDPWM);
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) {
PINfanPWM = 255;
EEPROM.put(215, PINfanPWM);
PinFANPWM = 255;
EEPROM.put(215, PinFANPWM);
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: ");
@ -2077,7 +2077,7 @@ void POSTwifiSettings() {
void POSTsetOutput() {
byte OutputState = webserver.arg("state").toInt();
byte OutputNr = webserver.arg("output").toInt();
//PINledPWM = webserver.arg("PINledPWM").toInt();
//PinLEDPWM = webserver.arg("PinLEDPWM").toInt();
byte OutputPWM = webserver.arg("OutputPWM").toInt();
Serial.println(":: POSTsetOutput ::");
@ -2190,19 +2190,19 @@ void APIgetSensors() {
switch(valWaterlevel) {
case 0:
digitalWrite(PINled, HIGH);
digitalWrite(PINpump, LOW);
digitalWrite(PINfan, LOW);
digitalWrite(PinLED, HIGH);
digitalWrite(PinPUMP, LOW);
digitalWrite(PinFAN, LOW);
break;
case 1:
digitalWrite(PINled, LOW);
digitalWrite(PINpump, HIGH);
digitalWrite(PINfan, LOW);
digitalWrite(PinLED, LOW);
digitalWrite(PinPUMP, HIGH);
digitalWrite(PinFAN, LOW);
break;
case 2:
digitalWrite(PINled, LOW);
digitalWrite(PINpump, LOW);
digitalWrite(PINfan, HIGH);
digitalWrite(PinLED, LOW);
digitalWrite(PinPUMP, LOW);
digitalWrite(PinFAN, HIGH);
break;
}
@ -2260,15 +2260,15 @@ void APIgetSensors() {
/* if(D6status == true) {
digitalWrite(PINled, LOW);
digitalWrite(PINpump, LOW);
digitalWrite(PINfan, LOW);
digitalWrite(PinLED, LOW);
digitalWrite(PinPUMP, LOW);
digitalWrite(PinFAN, LOW);
D6status = false;
Serial.println("D6 is off now");
} else {
digitalWrite(PINled, HIGH);
digitalWrite(PINpump, HIGH);
digitalWrite(PINfan, HIGH);
digitalWrite(PinLED, HIGH);
digitalWrite(PinPUMP, HIGH);
digitalWrite(PinFAN, HIGH);
D6status = true;
Serial.println("D6 is ON now");
}
@ -2277,14 +2277,14 @@ void APIgetSensors() {
/*
for(int dutyCycle = 0; dutyCycle < 255; dutyCycle++){
// changing the LED brightness with PWM
analogWrite(PINled, dutyCycle);
analogWrite(PinLED, dutyCycle);
delay(1);
}
// decrease the LED brightness
for(int dutyCycle = 255; dutyCycle > 0; dutyCycle--){
// changing the LED brightness with PWM
analogWrite(PINled, dutyCycle);
analogWrite(PinLED, dutyCycle);
delay(1);
}
*/