#include<stdio.h>
#include<driver/gpio.h>
#include<driver/adc.h>
#include <rom/ets_sys.h> // for ets_delay_us()
#include <unistd.h>
extern "C" void app_main() {
int val = 0;
float BETA = 3950.0, temp = 0.0;
while(true){
adc1_config_width(ADC_WIDTH_BIT_12);
adc1_config_channel_atten(ADC1_CHANNEL_4, ADC_ATTEN_DB_0);
val = adc1_get_raw(ADC1_CHANNEL_4);
printf("Resistor: \t%3d\n",val);
ets_delay_us(100000);
adc1_config_width(ADC_WIDTH_BIT_10); // SENSOR require it
adc1_config_channel_atten(ADC1_CHANNEL_7, ADC_ATTEN_DB_0);
val = adc1_get_raw(ADC1_CHANNEL_7);
temp = 1 / (log(1.0 / (1023. / (float)val - 1)) / BETA + 1.0 / 298.15) - 273.15;
printf("Temperaure: \t%3.2f\n",temp);
ets_delay_us(3000000);
printf("--------------\n");
}
}