#include <stdio.h>
#include <stddef.h>
#include <driver/gpio.h>
#include <freertos/FreeRTOS.h>
#include <freertos/queue.h>
#include <freertos/task.h>
//#include <D:/PlatformIO/Internet-of-Things-with-ESP32-main/common/esp-idf-lib/components/dht/dht.h>
//#include <D:/PlatformIO/Internet-of-Things-with-ESP32-main/common/ESP32-HD44780/components/HD44780/HD44780.h>
#include <dht.h>
#include <HD44780.h>
#define DHT_pin 14
#define push_button 3
#define LED 3
#define push_button_sel (1ULL<<push_button)
#define LED_sel (1ULL<<LED)
#define sda 16
#define scl 17
static void push_button_handler(void*);
static void init_hw(void){
gpio_config_t io_config;
//Push Button
io_config.mode=GPIO_MODE_INPUT;
io_config.pin_bit_mask=push_button_sel;
io_config.intr_type=GPIO_INTR_NEGEDGE;
io_config.pull_up_en=true;
io_config.pull_down_en=0;
gpio_config(&io_config);
gpio_install_isr_service(ESP_INTR_FLAG_LEVEL3); //Flag 0 is default
gpio_isr_handler_add(push_button,push_button_handler,NULL);
io_config.mode=GPIO_MODE_OUTPUT;
io_config.pin_bit_mask=LED_sel;
io_config.intr_type=GPIO_INTR_DISABLE;
io_config.pull_up_en=0;
io_config.pull_down_en=0;
gpio_config(&io_config);
//Test LED
}
static TickType_t next=0;
static int16_t Temperature;
static int16_t Humidity;
static bool led_state=false;
static void /*IRAM_ATTR*/ push_button_handler(void* arg){
TickType_t now=xTaskGetTickCountFromISR();
if (now>next){
ets_printf("/n button pressed"); //printf shoudn't be used in ISR
led_state=!led_state;
gpio_set_level(LED,led_state);
if( dht_read_data(DHT_TYPE_DHT11 , (gpio_num_t) DHT_pin, &Humidity,&Temperature)==ESP_OK)
ets_uart_printf("Temperature=%d%% Temp=%dC\n", Temperature/10, Humidity/10);
else
ets_uart_printf("/nFailure");
next=now+100/portTICK_PERIOD_MS;
}
}
void app_main() {
init_hw();
printf("going to sleep/n");
vTaskSuspend(NULL);
}
Loading
esp32-c3-devkitm-1
esp32-c3-devkitm-1