#pragma XOD evaluate_on_pin disable
#pragma XOD evaluate_on_pin enable input_UPD
#pragma XOD error_raise enable
#define referenceResistance 10000
#define nominalResistance 10000
#define nominalTemperature 298.15
#define bValue 3950
#define adcres 1023
struct State {
};
{{ GENERATED_CODE }}
void evaluate(Context ctx) {
if (!isInputDirty<input_UPD>(ctx))
return;
const uint8_t port = getValue<input_PORT>(ctx);
if (!isValidAnalogPort(port)) {
raiseError(ctx);
return;
}
::pinMode(port, INPUT);
double avgR = 0;
for(int i = 0; i < 10; i++){
avgR += analogRead(port);
delay(100);
}
avgR /= 10;
//avgR = 476;
avgR = referenceResistance / (adcres / avgR - 1);
double inverseKelvin = 1.0 / nominalTemperature + log(avgR / nominalResistance) / bValue;
double Celsius = 1.0/inverseKelvin - 273.15;
emitValue<output_VAL>(ctx, Celsius);
emitValue<output_DONE>(ctx, 1);
}