Good day,
I have a doubt about a function. I can not explain what does the &swp
I think you do not to try to understand all the function. This function is used to calculate the Soil Water Potention (swp) of the soil crop.
I need some parameter
- analog pin used to read the value
- a pin to power the sensor
- a delay (Not done yet)
- the temperature of the soil
The calculated value is store in swp
int16_t val2 = 0;
read(14,10,5000,24,val2);
Serial.println(val2)
It's work, but I can not explain why I need to have & before swp in the bellow function.
Is to make sure to have a pointer at the begining of the variable, but I do not need to do the same for Tsoil.
The difference between Tsoil and swp, swp is used to return a calculated value
bool EcoIrrigation::read(int analogPin, int powerPin, unsigned long timeout, int16_t Tsoil, int16_t &swp)
{
read(analogPin, powerPin, timeout, Tsoil, swp, false);
}
bool EcoIrrigation::read(int analogPin, int powerPin, unsigned long timeout, int16_t Tsoil, int16_t &swp, bool debug) // , bool debug = false
{
/*
* TODO: Add the timeout
*/
if(debug)
Serial.println(F("\tPowering the Watermark sensor"));
digitalWrite(powerPin, HIGH);
if(debug)
Serial.println(F("\tNeed a delay for the sensor to be in equilibre with the soil."));
delay(3000);
int highInput, lowInput; // Store high and low time of wave in microseconds
float totalInput; // Temp store of total time of duration for one cycle of high and low pulse
float frequency; // calculated freqency 1/total time of one cycle.
int16_t swp_shock; // store the swp calculate with Shock
int percent=0;
int32_t wrm; // Resistance of the sensors calculate from the frenquency returned by EcoIrrigation board output
//int32_t wrm2;
highInput = pulseIn(analogPin,HIGH);
lowInput = pulseIn(analogPin,LOW);
totalInput = highInput + lowInput;
frequency = 1000000 / totalInput;
if (highInput >0 && lowInput>0)
{
if(debug)
Serial.print(F("\tFrequency: ")); Serial.print((int16_t)frequency); Serial.print(F("Hz\t"));
}
else
{
if(debug)
Serial.print(F("\tfrequency: Error "));
return false;
}
delay(100);
if(debug)
Serial.println(F("\tPowering OFF the Watermark sensor"));
digitalWrite(powerPin, LOW);
delay(500);
/*
* Calculate the resistance in the soil
*/
if(debug)
Serial.println(F("\tCalculate the resistance of the sensor with measured frenquence (LMC555 Time)"));
resistanceCalc(frequency, wrm); // Get the resistance of the sensors from the frequemcy
wrm = constrain(wrm,550,27950); // Contrain de value from the minimum
if(debug)
{
Serial.print(F("\tWRM: "));
Serial.print(wrm); Serial.print(F(" Ohm"));
}
/*
* Calculation of the Soil Water Potetial
*/
swp=0;
// The temperature of te soil is needed. If that value does not exist, the scriot consider a temperazure of 24°C
if(Tsoil == NULL)
{
if(debug)
Serial.println(F("Tsoil is NULL"));
Tsoil = 24;
}
if(debug)
{
Serial.print(F("DEBUG Tsoil: "));
Serial.println(Tsoil);
}
/*
* Converion following a table provided by the manufacturer
*/
kPaCalc(wrm, Tsoil, swp, debug);
Serial.print(F("\tSWP: ")); Serial.print(swp); Serial.println(F(" kpa"));
/*
* Converion with the equation of shock
* We do not use it any more to calcuate the SWP as we use the table provided by the manufacturer.
* But I keep it to compare the value or for a future need
*/
swp_shock = kPaCalc_shock(wrm,Tsoil); // Conversion with the Shock
swp_shock = constrain(swp_shock,0,200);
if(debug)
{
Serial.print(F("SWPs: "));
Serial.print(swp_shock);
Serial.println(F(" kpa (Shock)"));
}
return true;
}
Many thanks
