#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_adc/adc_oneshot.h"
#define NUM_SAMPLES 128
float ntc_to_temperature(int adc_raw) {
float k = (float)adc_raw / 4095.0;
}
void app_main(void)
{
printf("Hello, Wokwi!\n");
adc_oneshot_unit_handle_t adc1_handle;
adc_oneshot_unit_init_cfg_t init_config1 = {
.unit_id = ADC_UNIT_1,
.ulp_mode = ADC_ULP_MODE_DISABLE,
};
ESP_ERROR_CHECK(
adc_oneshot_new_unit(&init_config1, &adc1_handle)
);
adc_oneshot_chan_cfg_t config = {
.bitwidth = ADC_BITWIDTH_DEFAULT,
.atten = ADC_ATTEN_DB_12,
};
ESP_ERROR_CHECK(
adc_oneshot_config_channel(
adc1_handle,
ADC_CHANNEL_3,
&config
)
);
while (true) {
int adc_raw;
long sum = 0;
for (int i = 0; i < NUM_SAMPLES; i++) {
ESP_ERROR_CHECK(
adc_oneshot_read(
adc1_handle,
ADC_CHANNEL_3,
&adc_raw
)
);
sum += adc_raw;
}
int adc_avg = sum / NUM_SAMPLES;
printf("ADC avg (%d samples): %d\n", NUM_SAMPLES, adc_avg);
vTaskDelay(pdMS_TO_TICKS(100));
}
}