实物链接:https://m.tb.cn/h.5iCUX6H?tk=PL65WXCEipQ CZ3457
1、设计一个触摸屏作为人机交互
2、通过触摸屏设置时间定时喂食喂水通风
3、获取当前水槽的水位并显示
4、获取环境温湿度并显示
1、触摸屏采用2.8寸电阻触摸屏
2、单片机采用STM32F407ZGT6
3、喂水使用直流水泵
4、喂食使用舵机
5、通风使用风扇
6、控制开关使用继电器
7、温湿度获取使用DHT11
8、水位检测使用水位传感器
1、UI使用LVGL
2、UI设计环境使用SquareLine Studio
3、生成代码导入到vsCode进行仿真运行,编译比较快
4、调试UI界面比较满意后导入UI代码到keil5下载到单片机运行
2、继电器控制电路设计
3、水泵和舵机电路设计
2、导入生成的UI代码
3、编写IO控制程序,舵机控制程序,系统时间、定时喂食喂水程序、事件记录程序
void scan_timeout(void)
{
int32_t remain_time[SCAN_TIME_NUM];
static int32_t p_time = 0x7fffffff;
static uint8_t p_num;
TimeTypeDef remain_time_min = {0};
char sprbuff[64];
int32_t n_num = 0;
char buff[SCAN_TIME_NUM][8] = {"喂食","喂食","喂水","喂水","通风","通风"};
char * pbuf = NULL;
get_sys_date_time();//获取系统时间
remain_time[0] = time_compare(&System.para.systime,&System.para.feed.time1 );//计算时间差
remain_time[1] = time_compare(&System.para.systime,&System.para.feed.time2 );//计算时间差
remain_time[2] = time_compare(&System.para.systime,&System.para.feedwater.time1);//计算时间差
remain_time[3] = time_compare(&System.para.systime,&System.para.feedwater.time2);//计算时间差
remain_time[4] = time_compare(&System.para.systime,&System.para.ventilate.time1);//计算时间差
remain_time[5] = time_compare(&System.para.systime,&System.para.ventilate.time2);//计算时间差
for(int i=0; i<SCAN_TIME_NUM; i++) //看看时间差哪个短 找到最短那个任务优先执行
{
if(p_time > remain_time[i] && remain_time[i] >= 0)
{
remain_time_min.hour = remain_time[i] / 3600;
remain_time_min.min = remain_time[i] % 3600 /60;
remain_time_min.sec = remain_time[i] % 60;
p_time = remain_time[i];
pbuf = buff[i];
p_num = i;
if(p_time == 0)p_time = 0x7fffffff;
printf("i = %d, remain_time[i]=%d\r\n",i,remain_time[i]);
}
if(remain_time[i] < 0)
{
n_num ++;
}
}
if(n_num != SCAN_TIME_NUM) //今天任务做完了吗? 哦 没有就进去
{
if(p_time < 30) //如果距离任务还不到 XXX秒了,就进来运行任务
{
switch(p_num)
{
case 0:
sprintf(sprbuff,"喂食时间到! %02d:%02d", System.para.feed.time1.hour,System.para.feed.time1.min);
SW1_ON();
break;
case 1:
sprintf(sprbuff,"喂食时间到! %02d:%02d", System.para.feed.time2.hour,System.para.feed.time2.min);
SW1_ON();
break;
case 2:
sprintf(sprbuff,"喂水时间到! %02d:%02d", System.para.feedwater.time1.hour,System.para.feedwater.time1.min);
SW2_ON();
break;
case 3:
sprintf(sprbuff,"喂水时间到! %02d:%02d", System.para.feedwater.time2.hour,System.para.feedwater.time2.min);
SW2_ON();
break;
case 4:
sprintf(sprbuff,"通风时间到! %02d:%02d", System.para.ventilate.time1.hour,System.para.ventilate.time1.min);
SW3_ON();
break;
case 5:
sprintf(sprbuff,"通风时间到! %02d:%02d", System.para.ventilate.time2.hour,System.para.ventilate.time2.min);
SW3_ON();
break;
}
lv_label_set_text(ui_MainInfoLabel7,sprbuff);
}
else if(pbuf != NULL)
{
sprintf(sprbuff,"主线任务 - %s %02d:%02d:%02d",pbuf,remain_time_min.hour,remain_time_min.min,remain_time_min.sec);
printf("%s\r\n",sprbuff);
lv_label_set_text(ui_MainInfoLabel7,sprbuff);
switch_all_off();
}
}else
{
lv_label_set_text(ui_MainInfoLabel7,"今日暂无任务");
}
}