赞
踩
目录
项目成品图片:
哔哩哔哩视频链接:
(资料分享见文末)
基于STM32的智能家居(机智云)系统。
功能如下:
- int main(void)
- {
- u8 t=0;
- int key_value; //按键值
- uart_init(115200); //串口初始化为115200
- delay_init(); //延时函数初始化
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置中断优先级分组为组2:2位抢占优先级,2位响应优先级
- Adc1_Channe_Init(); //ADC通道初始化
- KEY_Init(); //按键引脚初始化
- bmp280Init();
- //while(DHT11_Init());
- LED_Init(); //初始化与LED连接的硬件接口
- MOTOR_Init();
- OLED_Init(); //OLED初始化
- OLED_Clear(); //OLED清屏
- Gizwits_Init();
- gizwitsSetMode(WIFI_AIRLINK_MODE);//Air-link模式接入
- delay_ms(500);
- while(1)
- {
- Get_Data(0);
- if(gz_value<=A_gz_value&&mode==0)
- {
- LED0=0;
- curtain_flag=0;
- }else if(gz_value>A_gz_value&&mode==0){
- LED0=1;
- curtain_flag=1;
- }
- if(last_curtain_flag!=curtain_flag&&mode==0)
- {
- BUJING_Cotrol(curtain_flag,3,270);
- last_curtain_flag = curtain_flag;
- }
- if(last_curtain_flag!=currentDataPoint.valueCurtain&&mode==1)
- {
- BUJING_Cotrol(currentDataPoint.valueCurtain,3,270);
- curtain_flag = currentDataPoint.valueCurtain;
- last_curtain_flag = currentDataPoint.valueCurtain;
- }
- if(mode==1)
- {
- LED0=!currentDataPoint.valueLED;
- }
- if(DHT11_Temp>=A_DHT11_Temp||DHT11_Hum<=A_DHT11_Hum||Pre>=A_pre||m135_value<=A_m135_value||m2_value>=A_m2_value||m7_value>=A_m7_value)
- {
- BEEP=!BEEP;
- }else BEEP = 0;
-
- key_value = KEY_Scan(0);
- if(key_value==2)
- {
- display_contrl++;
- }
- if(display_contrl%2==0&&t>=10)
- {
- OLED_ShowCHinese(0,0,0);
- OLED_ShowCHinese(16,0,2);
- sprintf((char*)buff,":%2dC",DHT11_Temp);
- OLED_ShowString(32,0,buff,16); //显示温度
- OLED_ShowCHinese(64,0,1);
- OLED_ShowCHinese(82,0,2);
- sprintf((char*)buff,":%2d%%",DHT11_Hum);
- OLED_ShowString(96,0,buff,16);//显示湿度
-
- OLED_ShowCHinese(0,2,3);
- OLED_ShowCHinese(16,2,4);
- sprintf((char*)buff,":%2dhpa ",Pre);
- OLED_ShowString(32,2,buff,16);//显示气压
-
- OLED_ShowCHinese(0,4,5);
- OLED_ShowCHinese(16,4,6);
- OLED_ShowCHinese(32,4,7);
- OLED_ShowCHinese(48,4,8);
- sprintf((char*)buff,":%4dppm",gz_value);
- OLED_ShowString(64,4,buff,16);//显示光照强度
-
- OLED_ShowCHinese(0,6,9);
- OLED_ShowCHinese(16,6,10);
- OLED_ShowCHinese(32,6,11);
- OLED_ShowCHinese(48,6,12);
- sprintf((char*)buff,":%4dppm",m135_value);
- OLED_ShowString(64,6,buff,16);//显示空气质量
- }else if(display_contrl%2==1&&t>=10)
- {
- OLED_ShowCHinese(0,0,13);
- OLED_ShowCHinese(16,0,14);
- OLED_ShowCHinese(32,0,15);
- OLED_ShowCHinese(48,0,16);
- sprintf((char*)buff,":%4dppm",m2_value);
- OLED_ShowString(64,0,buff,16);//显示M2数据
-
- OLED_ShowCHinese(0,2,17);
- OLED_ShowCHinese(16,2,18);
- OLED_ShowCHinese(32,2,19);
- OLED_ShowCHinese(48,2,20);
- sprintf((char*)buff,":%4dppm",m7_value);
- OLED_ShowString(64,2,buff,16);//显示M7数据
-
- OLED_ShowCHinese(0,4,5);
- OLED_ShowCHinese(16,4,6);
- OLED_ShowCHinese(32,4,7);
- OLED_ShowCHinese(48,4,8);
- sprintf((char*)buff,":%4dppm",gz_value);
- OLED_ShowString(64,4,buff,16);//显示光照强度
-
- OLED_ShowCHinese(0,6,9);
- OLED_ShowCHinese(16,6,10);
- OLED_ShowCHinese(32,6,11);
- OLED_ShowCHinese(48,6,12);
- sprintf((char*)buff,":%4dppm",m135_value);
- OLED_ShowString(64,6,buff,16);//显示M135数据
- }
- userHandle(); //用户数据采集
- WIFI_Contection(key_value);//WiFi连接控制
- gizwitsHandle((dataPoint_t *)¤tDataPoint);//机智云协议处理
- Canshu_Change(key_value);
- t++;
- delay_ms(100);
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。