代碼:
import RPi.GPIO as GPIO
import Adafruit_DHT
import I2C_LCD_driver
import time
mylcd = I2C_LCD_driver.lcd()
DHT_TYPE = Adafruit_DHT.DHT22
DHT_PIN = 4
while True:
mylcd.lcd_display_string("Time: %s" %time.strftime("%H:%M:%S"), 1)
mylcd.lcd_display_string("Date: %s" %time.strftime("%m/%d/%Y"), 2)
humidity, temp = Adafruit_DHT.read(DHT_TYPE, DHT_PIN)
mylcd.lcd_display_string("Humidity: %d %%" % humidity, 4)
mylcd.lcd_display_string("temperature: %d C" % temp, 3)