int main(void) { const float freezingCelsius = 0; const float boilingCelsius = 100; puts("Freezing Point"); printf("Celsius: %f\n", freezingCelsius); printf("Fahrenheit: %f\n", celsiusToFahrenheit(freezingCelsius)); printf("Kelvin: %f\n\n", celsiusToKelvin(freezingCelsius)); puts("Boiling Point"); printf("Celsius: %f\n", boilingCelsius); printf("Fahrenheit: %f\n", celsiusToFahrenheit(boilingCelsius)); printf("Kelvin: %f\n", celsiusToKelvin(boilingCelsius)); return EXIT_SUCCESS; }
/*---------------------------------------------------------------------------*/ float t100::getColdJunctionTemperature() { int16_t tmp16; float temperature; /* Convert raw data to celsius */ /* TODO: Add additional eq function */ tmp16 = (internalBuffer[5] << 8) | internalBuffer[6]; tmp16 = tmp16 >> 4; temperature = tmp16 * 0.0625; /* Return the temperature value in correct unit */ if(this->temperatureUnit == T100_CELCIUS) { return temperature; } else if(this->temperatureUnit == T100_KELVIN) { return celsiusToKelvin(temperature); } else if(this->temperatureUnit == T100_FAHRENHEIT) { return celsiusToFahreneit(temperature); } else { return 99999.0; /* error ... */ } }
void getTemp() { uint16_t last_sample = 0; double this_temp; double temp_avg; uint16_t i; temp_avg = 0.0; for (i=0; i<500; i++) { last_sample = adc_read(); this_temp = sampleToFahrenheit(last_sample); temp_avg = temp_avg + this_temp/500.0; } double c = fahrenheitToCelsius(temp_avg); double k = celsiusToKelvin(c); // write message to LCD lcd_init(); FILE lcd_stream = FDEV_SETUP_STREAM(lcd_putchar, 0, _FDEV_SETUP_WRITE); lcd_home(); lcd_write_string(PSTR("ADC: ")); lcd_write_int16(last_sample); lcd_write_string(PSTR(" of 1024 ")); lcd_line_two(); fprintf_P(&lcd_stream, PSTR("%.2f"), temp_avg); lcd_write_data(0xdf); lcd_write_string(PSTR("F")); lcd_line_three(); fprintf_P(&lcd_stream, PSTR("%.2f"), c); lcd_write_data(0xdf); lcd_write_string(PSTR("C")); lcd_line_four(); fprintf_P(&lcd_stream, PSTR("%.2f"), k); lcd_write_data(0xdf); lcd_write_string(PSTR("K")); }
/*---------------------------------------------------------------------------*/ float t100::getThermocoupleTemperature() { float temperature; int partialGroupCount; float thermocouple_mv; TCCOEF_TYPEDEF partialCoeff; const TCCOEF_TYPEDEF* currentCoeffs; /* Get the correct data coefficients */ /* NOTE: We expect a valid 'thermocoupleTypeInd' here. */ currentCoeffs = ThermoCoeffArray[this->thermocoupleTypeInd].coeff; partialGroupCount = ThermoCoeffArray[this->thermocoupleTypeInd].partialCoeffCount; /* Let's get the current thermocouple voltage */ thermocouple_mv = getAdcVoltage(); /* Let's check the boundaries of the current thermocouple data type */ if(thermocouple_mv < currentCoeffs[0].mV_LOW) { /* Our current TC voltage is lower than the lowest */ return T100_TEMP_MIN; } else if(thermocouple_mv > currentCoeffs[(partialGroupCount-1)].mV_HIGH) { /* Our current TC voltage is higher than the highest */ return T100_TEMP_MAX; } /* OK, we are in limits but which partial group should we use? */ for(int i=0; i<partialGroupCount; i++) { if((thermocouple_mv >= currentCoeffs[i].mV_LOW) && (thermocouple_mv <= currentCoeffs[i].mV_HIGH)) { /* Store the final coeff we are going to use */ partialCoeff = currentCoeffs[i]; /* Break the loop */ i = 999; } } /* Calculate the polynomial result */ temperature = getColdJunctionTemperature_celsius(); temperature += partialCoeff.coeff[0]; for(int i=1; i<10; i++) { temperature += partialCoeff.coeff[i] * pow(thermocouple_mv,i); } /* Convert the temperature if neccessary */ if(this->temperatureUnit == T100_KELVIN) { temperature = celsiusToKelvin(temperature); } else if(this->temperatureUnit == T100_FAHRENHEIT) { temperature = celsiusToFahreneit(temperature); } return temperature; }