Prevent moisture to exceed range from 0-100 percent.
This commit is contained in:
parent
4d685c8edf
commit
d64710a841
@ -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);}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user