#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
//#include "driver/adc.h"
#include "esp_adc/adc_oneshot.h"
#include "esp_adc/adc_continuous.h"
#include "esp_log.h"
#include "sdkconfig.h"
#include "driver/gpio.h"
#define NTC_PIN ADC1_CHANNEL_9 // GPIO 10 é ADC1_CH3
#define PUSH_BUTTON 4
#define BUZZER_PIN 9
#define LED_RED 5 // LED RGB
#define LED_GREEN 6 // LED RGB
#define LED_BLUE 7 // LED RGB
float converte_celsius (adc_value) {
const float BETA = 3950;
float celsius = 0;
celsius = (1 / ((log(1 /(1-1023.0/adc_value -1))/BETA) + 1.0/298.15)) - 273.15;
return celsius;
}
void app_main() {
gpio_set_direction (PUSH_BUTTON, GPIO_MODE_INPUT); //botão como entrada
gpio_set_direction(BUZZER_PIN, GPIO_MODE_OUTPUT); //buzzer como saida
gpio_set_direction(LED_RED, GPIO_MODE_OUTPUT); //LED como saida
gpio_set_direction(LED_GREEN, GPIO_MODE_OUTPUT); //LED como saida
gpio_set_direction(LED_BLUE, GPIO_MODE_OUTPUT); //LED como saida
float celsius = 0;
//SILENCIAR BUZZER
if (gpio_get_level (PUSH_BUTTON == 1)) {
vTaskDelay(3000 / portTICK_PERIOD_MS);
gpio_set_level (BUZZER_PIN, 0);
}
//Leitura NTC
adc1_config_width(ADC_WIDTH_BIT_12);
adc1_config_channel_atten(ADC1_CHANNEL_9, ADC_ATTEN_DB_11);
while (1)
{
int adc_value = adc1_get_raw(ADC1_CHANNEL_9);
printf("ADC Value: %d", adc_value);
printf("\n");
printf ("Celsius: %d", converte_celsius (adc_value));
vTaskDelay(500/ portTICK_PERIOD_MS);
}
}