//boolean S == Scale. True == Fahrenheit; False == Celcius float DHT::readTemperature(bool S, bool force) { float f = NAN; if (read(force)) { switch (_type) { case DHT11: f = data[2]; if(S) { f = convertCtoF(f); } break; case DHT22: case DHT21: f = data[2] & 0x7F; f *= 256; f += data[3]; f *= 0.1; if (data[2] & 0x80) { f *= -1; } if(S) { f = convertCtoF(f); } break; } } return f; }
//boolean S == Scale. True == Farenheit; False == Celcius float DHT::readTemperature(bool S) { float f; if (read()) { switch (_type) { case DHT11: f = data[2]; if(S) f = convertCtoF(f); return f; case DHT22: case DHT21: f = data[2] & 0x7F; f *= 256; f += data[3]; f /= 10; if (data[2] & 0x80) f *= -1; if(S) f = convertCtoF(f); return f; } } // Serial.print("Read fail"); return NAN; }
//boolean S == Scale. True == Farenheit; False == Celcius float DHT::readTemperature(bool S) { float f; if (read()) { switch (_type) { case DHT11: f = data[2]; if (S) f = convertCtoF(f); temperature = f; return f; case DHT22: case DHT21: f = data[2] & 0x7F; f *= 256; f += data[3]; f /= 10; if (data[2] & 0x80) f *= -1; if (S) f = convertCtoF(f); temperature = f; return f; } } return 0.0; }
//boolean S == Scale. True == Farenheit; False == Celcius float DHT::readTemperature(bool S) { float _f; if (read()) { switch (_type) { case DHT11: _f = data[2]; if(S) _f = convertCtoF(_f); return _f; case DHT22: case DHT21: _f = data[2] & 0x7F; _f *= 256; _f += data[3]; _f /= 10; if (data[2] & 0x80) _f *= -1; if(S) _f = convertCtoF(_f); return _f; } } return NAN; }
//boolean isFahrenheit: True == Fahrenheit; False == Celcius float DHT::computeHeatIndex(float temperature, float percentHumidity, bool isFahrenheit) { // Using both Rothfusz and Steadman's equations // http://www.wpc.ncep.noaa.gov/html/heatindex_equation.shtml float hi; if (!isFahrenheit) temperature = convertCtoF(temperature); hi = 0.5 * (temperature + 61.0 + ((temperature - 68.0) * 1.2) + (percentHumidity * 0.094)); if (hi > 79) { hi = -42.379 + 2.04901523 * temperature + 10.14333127 * percentHumidity + -0.22475541 * temperature*percentHumidity + -0.00683783 * pow(temperature, 2) + -0.05481717 * pow(percentHumidity, 2) + 0.00122874 * pow(temperature, 2) * percentHumidity + 0.00085282 * temperature*pow(percentHumidity, 2) + -0.00000199 * pow(temperature, 2) * pow(percentHumidity, 2); if((percentHumidity < 13) && (temperature >= 80.0) && (temperature <= 112.0)) hi -= ((13.0 - percentHumidity) * 0.25) * sqrt((17.0 - abs(temperature - 95.0)) * 0.05882); else if((percentHumidity > 85.0) && (temperature >= 80.0) && (temperature <= 87.0)) hi += ((percentHumidity - 85.0) * 0.1) * ((87.0 - temperature) * 0.2); } return isFahrenheit ? hi : convertFtoC(hi); }
float DHT::computeHeatIndex(float temperature, float percentHumidity, bool isFahrenheit) { float heatIndex; if (!isFahrenheit) temperature = convertCtoF(temperature); heatIndex = 0.5 * (temperature + 61.0 + ((temperature - 68.0) * 1.2) + (percentHumidity * 0.094)); if (heatIndex > 79) { heatIndex = -42.379 + 2.04901523 * temperature + 10.14333127 * percentHumidity + -0.22475541 * temperature*percentHumidity + -0.00683783 * pow(temperature, 2) + -0.05481717 * pow(percentHumidity, 2) + 0.00122874 * pow(temperature, 2) * percentHumidity + 0.00085282 * temperature*pow(percentHumidity, 2) + -0.00000199 * pow(temperature, 2) * pow(percentHumidity, 2); if((percentHumidity < 13) && (temperature >= 80.0) && (temperature <= 112.0)) heatIndex -= ((13.0 - percentHumidity) * 0.25) * sqrt((17.0 - abs(temperature - 95.0)) * 0.05882); else if((percentHumidity > 85.0) && (temperature >= 80.0) && (temperature <= 87.0)) heatIndex += ((percentHumidity - 85.0) * 0.1) * ((87.0 - temperature) * 0.2); } //boolean isFahrenheit: True == Fahrenheit; False == Celcius return isFahrenheit ? heatIndex : convertFtoC(heatIndex); }
float DHT::readTemperature(bool bFarenheit/* = false*/) { read(); if (NAN != m_lastTemp && bFarenheit) return convertCtoF(m_lastTemp); else return m_lastTemp; }
//This function gets the two bytes of temperature data from the STTS751 Sensor and convert float temp value //This function was leveraged from blog post http://mike.saunby.net/2013_03_01_archive.html float WSNode::getSTTS751Temp() { byte lo; signed char hi; //Because the Address pin is tied to ground the STTS751 address is 0x3B Wire.begin(); // initialise the connection hi = i2c_sensor_read_byte(0x3B, 0); lo = i2c_sensor_read_byte(0x3B, 2); Wire.end(); //turn wire off until next reading if(tempSetF) { if( hi > 0) return convertCtoF(hi + lo * 1.0/256.0); else return convertCtoF(hi - lo * 1.0/256.0); } else { if( hi > 0) return (hi + lo * 1.0/256.0); else return (hi - lo * 1.0/256.0); } }
float ALB_DHT11::readTemperatureF() { float f = NAN; if (read()) { f = data[2]; f = convertCtoF(f); } return f; }
float DHT::readTemperature(bool S, bool force) { float f = NAN; if (read(force)) { f = data[2] & 0x7F; f *= 256; f += data[3]; f *= 0.1; if (data[2] & 0x80) { f *= -1; } if(S) { f = convertCtoF(f); } } return f; }
bool DHT::readTempAndHumidity(float* temp, float* humid, bool bFarenheit/* = false*/) { bool bSuccess = false; if (read()) { if(temp) { *temp = m_lastTemp; if(bFarenheit) { *temp = convertCtoF(*temp); } } if(humid) { *humid = m_lastHumid; } bSuccess = true; } return bSuccess; }
// The real aquire function Humiditysensor DHTHUMIDITY::readHumidity() { float u,t; if (readSensor()) { switch (sensor.Type) { case DHT11: u = data[0]; t = data[2]; break; case DHT22: case DHT21: u = data[0]; u *= 256; u += data[1]; u /= 10; t = data[2] & 0x7F; t *= 256; t += data[3]; t /= 10; if (data[2] & 0x80) t *= -1; break; default: u = 0; t = 0; break; } } else { Serial.print("Read fail"); u = -1; t = -1; } sensor.TemperatureC = t; sensor.TemperatureF = convertCtoF(t); sensor.Humidity = u; return(sensor); }
int main() { int choixMenu, h, m, s; //ENTIERS float tempC, tempF, distKM, distMI, volumeL, volumeG; //REELS do //DEBUT DE LA BOUCLE REPETER { AfficherMenu(); printf("\nVotre choix ? "); scanf("%d", &choixMenu); printf("\n"); //STRUCTURE CONDITIONNELLE switch (choixMenu) { case 1: // SI CHOIXMENU EST EGAL A 1 ALORS printf("Saisir heure(s)\n"); scanf("%d", &h); printf("Saisir minute(s)\n"); scanf("%d", &m); printf("Saisir seconde(s)\n"); scanf("%d", &s); printf("%d h, %d min, %d sec = %d secondes", h, m, s, convertHMStoS(h,m,s)); break; //ON SORT DU SWITCH case 2: printf("Saisir secondes\n"); scanf("%d", &s); printf("%d secondes =", s); //ON ENVOIE L'ADRESSE DE H M ET S decoupeSecondes(&h, &m, &s); printf(" %d heures et %d minutes et %d secondes", h, m, s); break; case 3: printf("saisir la temperature en degre C\n"); scanf("%f", &tempC); printf("%1.2f degre C = %1.2f degre F", tempC, convertCtoF(tempC)); break; case 4: printf("saisir la temperature en degre F\n"); scanf("%f",&tempF); printf("%1.2f degre F = %1.2f degre C", tempF, convertFtoC(tempF)); break; case 5: printf("saisir une distance en km\n"); scanf("%f", &distKM); printf("%1.2f km = %1.2f miles", distKM, convertKMtoMI(distKM)); break; case 6: printf("saisir une distance en milles\n"); scanf("%f", &distMI); printf("%1.2f mi = %1.2f km",distMI, convertMItoKM(distMI)); break; case 7: printf("saisir un volume en litres\n"); scanf("%f", &volumeL); printf("%1.2f L = %1.2f G", volumeL, convertLtoG(volumeL)); break; case 8: printf("saisir un volume en gallons\n"); scanf("%f", &volumeG); printf("%1.2f G = %1.2f L", volumeG, convertGtoL(volumeG)); break; case 9: printf("Au revoir\n"); } if (choixMenu < 1 || choixMenu > 9) printf("Erreur de saisie"); } while (choixMenu != 9); //JUSQU'AU TEMPS QUE CHOIXMENU EGAL A 9 return 0; }
float DHT::getHeatIndex() { return convertFtoC(computeHeatIndex(convertCtoF(readTemperature()), readHumidity())); }
float DHT::getTempFarenheit() { return convertCtoF(readTemperature()); }