找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 7|回复: 0
打印 上一主题 下一主题
收起左侧

基于stm32单片机的智能家居系统程序

[复制链接]
跳转到指定楼层
楼主
ID:755173 发表于 2026-4-14 08:53 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include "total_wifi.h"
#include "pub_sub_message.h"
#include "DMA_adc.h"
#include "show.h"
#include "time4.h"
#include "usart3.h"
#include "infrared.h"
#include "dht11.h"
#include "motorrun.h"        
void data_caiji(void);
void ctrl_auto(void);
extern char SubcribePack_flag;   
unsigned int SystemTimer = 0;   
unsigned int TEHUTimer = 0;     
extern __IO uint16_t ADC_ConvertedValue[NOFCHANEL];

int Learn_IR_ctrl[5] = {0xFA, 0xFD, 0x01, 0x00, 0xDF};

int IR_ctrl_on[5] = {0xFA, 0xFD, 0x02, 0x00, 0xDF};
int IR_ctrl_off[5] = {0xFA, 0xFD, 0x02, 0x01, 0xDF };

u8 light, ppm, co;
u16 adc_light, adc_ppm, adc_co;
u8 tem, hum, people;
u8 PPM_MAX = 50, co_MAX = 50;
int main(void)
{
    Delay_Init();                  
    Usart1_Init(9600);              
    uart3_init(9600);

   
    KEY_Init();                     
    KEY_Exti_Init();
    ADCx_Init();
    OLED_Init();
    WiFi_ResetIO_Init();            
    AliIoT_Parameter_Init();            
    LED_Init();
    MOTOR_Init();
    DHT11_Init();
    TIM2_ENABLE_200MS();
    while(1)                     
    {



                                                data_caiji();




    }
}
u8 people_num_sta,people_num;
void data_caiji(void)
{
    if(IO_A5_IN_STA)
    {
                        printf("1");
                        people_num=1;               
                        if(people_num!=people_num_sta)
                        {
                                people_num_sta=people_num;
                                people++;
                        }
    }
                else
                {        printf("0");
                        people_num_sta=0;
                }
    adc_light = Get_Adc_Average(0, 10);
    if(adc_light > 4000)adc_light = 4000;
    light = (100 - (adc_light / 40));

   
    adc_ppm = Get_Adc_Average(1, 10);
    ppm = adc_ppm * 99 / 4096;
    ppm = ppm >= 99 ? 99 : ppm;
   
   
    adc_co = Get_Adc_Average(2, 10);
    co = adc_co * 99 / 4096;
    co = co >= 99 ? 99 : co;
   
    DHT11_Read_Data(&hum, &tem);
}
u8 auto_flag ;
u8 ppm_beep, ppm_beep_sta;
u8 co_beep, co_beep_sta;
void ctrl_auto(void)
{
    char temp[500];
    if(auto_flag)
    {
        if(ppm > PPM_MAX)
        {
            BEEP = !BEEP;
            ppm_beep = 1;
                                                Delay_Ms(30);
            if(ppm_beep != ppm_beep_sta)
            {
                show_num = 4;
                ppm_beep_sta = ppm_beep;
                if(SubcribePack_flag)
                {
                    sprintf(temp, "{\"method\":\"thing.event.property.post\",\"id\":\"203302322\",\"params\":{\""identifier10"\":1},\"version\":\"1.0.0\"}");
                    MQTT_PublishQs0(P_TOPIC_NAME, temp, strlen(temp));
                }
            }
        }
        else if(ppm < PPM_MAX)
        {
            BEEP = 1;
            ppm_beep = 0;
            if(ppm_beep != ppm_beep_sta)
            {
                show_num = 0;
                ppm_beep_sta = ppm_beep;
                if(SubcribePack_flag)
                {
                    sprintf(temp, "{\"method\":\"thing.event.property.post\",\"id\":\"203302322\",\"params\":{\""identifier10"\":0},\"version\":\"1.0.0\"}");
                    MQTT_PublishQs0(P_TOPIC_NAME, temp, strlen(temp));
                }
            }
        }
        if(co > co_MAX)
        {
            BEEP = !BEEP;
                                                Delay_Ms(30);
            co_beep = 1;
            show_num = 4;
            if(co_beep != co_beep_sta)
            {
                co_beep_sta = co_beep;
                if(SubcribePack_flag)
                {
                    sprintf(temp, "{\"method\":\"thing.event.property.post\",\"id\":\"203302322\",\"params\":{\""identifier11"\":1},\"version\":\"1.0.0\"}");
                    MQTT_PublishQs0(P_TOPIC_NAME, temp, strlen(temp));
                }
            }
        }
        else if(co < co_MAX)
        {
            BEEP = 1;
            co_beep = 0;
            if(co_beep != co_beep_sta)
            {
                show_num = 0;
                co_beep_sta = co_beep;
                if(SubcribePack_flag)
                {
                    sprintf(temp, "{\"method\":\"thing.event.property.post\",\"id\":\"203302322\",\"params\":{\""identifier11"\":0},\"version\":\"1.0.0\"}");
                    MQTT_PublishQs0(P_TOPIC_NAME, temp, strlen(temp));
                }
            }
        }
    }

}

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表