Esempio n. 1
0
int8_t dht_cache(uint32_t systime){
	if (((uint32_t)(systime-cache_time)) > DHT_CACHE_TIMEOUT){
		if (dht_gettemperaturehumidity(&cached_temperature, &cached_humidity)){
			cache_time = systime;
			return 1;	//обновили кэш
		}
		return 0; // не удалось получить значения с датчика
	}
	return 1;	//можно брать из кэша
}
Esempio n. 2
0
float Get_Hum(void)
{
	char printbuff[100];
	int8_t temperature = 0;
	float humidity;
	dht_gettemperaturehumidity(&temperature, &humidity);
	dtostrf(temperature, 3, 3, printbuff);
	dtostrf(humidity, 3, 3, printbuff);

			 
	
	
	return humidity;
}
Esempio n. 3
0
int main(void)
{
	char printbuff[100];

	//init uart
	uart_init( UART_BAUD_SELECT(UART_BAUD_RATE,F_CPU) );

	//init interrupt
	sei();

	#if DHT_FLOAT == 0
	int8_t temperature = 0;
	int8_t humidity = 0;
	#elif DHT_FLOAT == 1
	float temperature = 0;
	float humidity = 0;
	#endif

	for (;;) {
		if(dht_gettemperaturehumidity(&temperature, &humidity) != -1) {

			#if DHT_FLOAT == 0
			itoa(temperature, printbuff, 10);
			#elif DHT_FLOAT == 1
			dtostrf(temperature, 3, 3, printbuff);
			#endif
			uart_puts("temperature: "); uart_puts(printbuff); uart_puts("C");uart_puts("\r\n");
			#if DHT_FLOAT == 0
			itoa(humidity, printbuff, 10);
			#elif DHT_FLOAT == 1
			dtostrf(humidity, 3, 3, printbuff);
			#endif
			uart_puts("humidity: "); uart_puts(printbuff); uart_puts("%RH");uart_puts("\r\n");

		} else {
			uart_puts("error"); uart_puts("\r\n");
		}

		uart_puts("\r\n");

		_delay_ms(1500);
	}
	
	return 0;
}