Prevent moisture to exceed range from 0-100 percent.

This commit is contained in:
Andrés Uribe Stengel 2020-07-01 16:54:11 +02:00
parent 4d685c8edf
commit d64710a841

View File

@ -24,5 +24,10 @@ int readCapacitiveSoilMoistureSensor()
Serial.println(measurement);
// add the reading to the total:
//int measurement = analogRead(PIN_MS);
return map(measurement, VALUE_AIR, VALUE_WATER, 0, 100);
if (map(measurement, VALUE_AIR, VALUE_WATER, 0, 100) < 0) {
return 0;
} else if (map(measurement, VALUE_AIR, VALUE_WATER, 0, 100) > 100) {
return 100;
} else {return map(measurement, VALUE_AIR, VALUE_WATER, 0, 100);}
}