1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| int main(void) { char str[] = ""; u16 PM = 0; DHT11_Data_TypeDef DHT11_Data; delay_init(); NVIC_Configuration(); uart_init(115200); GP2Y_Adc_Init(); OLED_Init(); OLED_ColorTurn(0); OLED_DisplayTurn(0);
OLED_Refresh(); OLED_ShowString(2,2,"PM2.5:",16); OLED_ShowString(12,20,"TEM:",16); OLED_ShowString(12,38,"HUM:",16); OLED_ShowString(90,2,"ug/m3",12); OLED_ShowChinese(100,20,0,16); OLED_ShowChar(100,38,'%',16); while(1) { PM = GetGP2YSingleValue(); if(PM < 10) sprintf(str, " %d ",PM); else if(PM < 100) sprintf(str, "%d ",PM); else sprintf(str, "%d",PM); OLED_ShowString(60,2,(u8 *)str,16); if( Read_DHT11(&DHT11_Data)==SUCCESS) { sprintf(str, "%d.%d ℃ ",DHT11_Data.temp_int,DHT11_Data.temp_deci); OLED_ShowString(60,20,(u8 *)str,16); sprintf(str, "%d.%d",DHT11_Data.humi_int,DHT11_Data.humi_deci); OLED_ShowString(60,38,(u8 *)str,16); } else { printf("Read DHT11 ERROR!\r\n"); }
OLED_Refresh(); delay_ms(1000); } }
|