五、关键代码
3.main.c主函数关键函数
关键函数,通过设定阈值进行判断,是否需要加水操作
if(length>20) //判断水位
{relay_on();;//水泵打开加水
while(1){
OLED_Clear();
OLED_ShowCHinese(0,0,25);
OLED_ShowCHinese(0,15,26);
OLED_ShowCHinese(0,30,27);
OLED_ShowCHinese(0,45,28);
OLED_ShowCHinese(0,60,29);
OLED_ShowCHinese(0,75,30);
OLED_ShowCHinese(0,90,31);
OLED_ShowCHinese(2,0,0);
OLED_ShowCHinese(2,20,1);
OLED_ShowCHinese(2,40,2);
OLED_ShowCHinese(2,60,3);
length = Hcsr04GetLength();
OLED_ShowNum(2, 75, length, 2);
OLED_ShowString(2,77, "cm");
OLED_ShowString(3,73, ">>");
OLED_ShowCHinese(5,80,11);
OLED_ShowCHinese(5,95,12);
delay_ms(500);
if(length<20) //判断水位
{relay_off();;//水泵关闭
break;}
}
}
|