#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_adc/adc_oneshot.h"
#include "esp_log.h"
#include "esp_err.h"
const static char *TAG = "ADC";
#define CONFIG_LOG_MAXIMUM_LEVEL 5
static int adc_raw = 0;
void app_main(void)
{
esp_log_level_set(TAG, ESP_LOG_VERBOSE);
adc_oneshot_unit_handle_t adc_handle = NULL;
adc_oneshot_unit_init_cfg_t init_config = {
.unit_id = ADC_UNIT_1,
.ulp_mode = ADC_ULP_MODE_DISABLE,
};
ESP_ERROR_CHECK(adc_oneshot_new_unit(&init_config, &adc_handle));
adc_oneshot_chan_cfg_t config = {
.bitwidth = ADC_BITWIDTH_DEFAULT,
.atten = ADC_ATTEN_DB_11,
};
ESP_ERROR_CHECK(adc_oneshot_config_channel(adc_handle, ADC_CHANNEL_6, &config));
while (1)
{
ESP_ERROR_CHECK(adc_oneshot_read(adc_handle, ADC_CHANNEL_6, &adc_raw));
ESP_LOGI(TAG, "ADC%d Channel %d -> Raw Data: %4d", ADC_UNIT_1 + 1, ADC_CHANNEL_6, adc_raw);
vTaskDelay(pdMS_TO_TICKS(200));
}
adc_oneshot_del_unit(adc_handle);
}