projet capteur connecté ST/SE

Dependencies:   HP206C mbed HMC5883L DHT DS1820

Committer:
MathieuM
Date:
Mon Dec 10 11:26:41 2018 +0000
Revision:
82:6f5913a97489
Parent:
60:8b65fdf54d56
Various updates

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Fayge 59:6d48aee9f7d5 1 #include "T_H_soil.h"
Fayge 59:6d48aee9f7d5 2
Fayge 60:8b65fdf54d56 3 bool initSoilTemp(DS1820 probe, PinName pin)
Fayge 59:6d48aee9f7d5 4 {
Fayge 59:6d48aee9f7d5 5 //check that a DS1820 is connected at its port and init it
Fayge 59:6d48aee9f7d5 6 return probe.unassignedProbe(pin);
Fayge 59:6d48aee9f7d5 7 }
Fayge 59:6d48aee9f7d5 8
Fayge 59:6d48aee9f7d5 9 float getSoilTemperature(DS1820& probe)
Fayge 59:6d48aee9f7d5 10 {
Fayge 60:8b65fdf54d56 11 bool wait(true);// if true, waits up to 750ms before returning(based on wented precision)
Fayge 59:6d48aee9f7d5 12 //return the ms_delay until the conversion will complete (=0 if wait == true)
Fayge 59:6d48aee9f7d5 13 int ms_delay = probe.convertTemperature(wait, DS1820::this_device);
Fayge 59:6d48aee9f7d5 14 if(ms_delay > 0)
Fayge 59:6d48aee9f7d5 15 wait_ms(ms_delay);
Fayge 59:6d48aee9f7d5 16
Fayge 59:6d48aee9f7d5 17 //grab and return the conversion result
Fayge 59:6d48aee9f7d5 18 return probe.temperature();
Fayge 60:8b65fdf54d56 19 //can return DS1820::invalid_conversion
Fayge 59:6d48aee9f7d5 20 }
Fayge 59:6d48aee9f7d5 21
Fayge 59:6d48aee9f7d5 22 float getSoilHumidity(AnalogIn& probe, float& airValue, float& waterValue, bool adaptiveCalibration)
Fayge 59:6d48aee9f7d5 23 {
Fayge 59:6d48aee9f7d5 24 float HumidSensorVal = probe.read();
Fayge 59:6d48aee9f7d5 25 float onePercent = (airValue - waterValue)/100;
Fayge 59:6d48aee9f7d5 26 float humidityPercentage = 100-(HumidSensorVal-waterValue)/onePercent;
Fayge 59:6d48aee9f7d5 27 if(humidityPercentage < 0 && adaptiveCalibration)// in case its drier than we expected at max
Fayge 59:6d48aee9f7d5 28 {
Fayge 59:6d48aee9f7d5 29 humidityPercentage = 0;
Fayge 59:6d48aee9f7d5 30 airValue = HumidSensorVal;
Fayge 59:6d48aee9f7d5 31 }
Fayge 59:6d48aee9f7d5 32 else if(humidityPercentage > 100 && adaptiveCalibration)// in case its wetter than we expected at max
Fayge 59:6d48aee9f7d5 33 {
Fayge 59:6d48aee9f7d5 34 humidityPercentage = 100;
Fayge 59:6d48aee9f7d5 35 waterValue = HumidSensorVal;
Fayge 59:6d48aee9f7d5 36 }
Fayge 59:6d48aee9f7d5 37 return humidityPercentage;
Fayge 60:8b65fdf54d56 38 }