#display
import board
import busio
import displayio
import terminalio
from adafruit_display_text import bitmap_label as label
import adafruit_displayio_sh1107
import adafruit_dht
import time
import adafruit_rgbled
# Pin the Red LED is connected to
RED = board.GP2
# Pin the Green LED is connected to
GREEN = board.GP1
# Pin the Blue LED is connected to
BLUE = board.GP0
# Create the RGB LED object
led = adafruit_rgbled.RGBLED(RED, GREEN, BLUE, invert_pwm=False)
i2c = busio.I2C(board.GP27, board.GP26)
dht = adafruit_dht.DHT22(board.GP17)
#DISPLAY
displayio.release_displays()
display_bus = displayio.I2CDisplay(i2c, device_address=0x3C)
# SH1107 is vertically oriented 123x128
WIDTH = 128
HEIGHT = 128
display = adafruit_displayio_sh1107.SH1107(display_bus, width=WIDTH, height=HEIGHT, rotation=180)
# Make the display context
splash = displayio.Group()
display.root_group = splash
# Draw some text
text= "Shell Electronics"
splash.append(label.Label(terminalio.FONT, text=text, color=0xFFFFFF, x=2, y=4))
text= "SD Flatres"
splash.append(label.Label(terminalio.FONT, text=text, color=0xFFFFFF, x=2, y=20))
time.sleep(2)
temperature = 0
humidity = 0
while True:
try:
temperature = dht.temperature
humidity = dht.humidity
# Print what we got to the REPL
print("T:" + str(temperature))
print("H:" + str(humidity))
#clear the screen
display.root_group = None
splash = displayio.Group()
display.root_group = splash
# Draw some text
text= "Temp: " + str(temperature)
splash.append(label.Label(terminalio.FONT, text=text, color=0xFFFFFF, x=2, y=4))
text= "Hum: " + str(humidity)
splash.append(label.Label(terminalio.FONT, text=text, color=0xFFFFFF, x=2, y=20))
time.sleep(2)
if temperature < 1:
led.color = (0, 0, 255)
elif temperature > 30:
led.color = (255, 0, 0)
else:
led.color = (0, 255, 0)
except RuntimeError as e:
continue
time.sleep(1)Loading
grove-oled-sh1107
grove-oled-sh1107