Files
Smart-granary-code/components/MQ-2/include/MQ-2.h

38 lines
617 B
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include "esp_err.h"
#ifdef __cplusplus
extern "C" {
#endif
// ESP32-S3: GPIO8 -> ADC1_CHANNEL_7
#define MQ2_ADC_GPIO 8
/**
* @brief 初始化 MQ-2 ADC 通道
*/
esp_err_t mq2_init(void);
/**
* @brief 读取 MQ-2 原始 ADC 值0~4095
*/
esp_err_t mq2_read_raw(int *raw_out);
/**
* @brief 读取 MQ-2 归一化百分比0~100
*/
esp_err_t mq2_read_percent(float *percent_out);
/**
* @brief 根据阈值判断是否疑似有害气体/烟雾超标
*/
bool mq2_is_alarm(float percent, float threshold_percent);
#ifdef __cplusplus
}
#endif