from machine import Pin
from time import sleep
import dht
sensor = dht.DHT22(Pin(28)) #refer to sensor data pin
DATAPINS = [Pin(11, Pin.OUT), Pin(10, Pin.OUT)] #DS
clockPin = Pin(12, Pin.OUT) #SHCP
LATCHPINS = [Pin(13, Pin.OUT), Pin(14, Pin.OUT)] #STCP
# Read sensor values
# sensor.measure()
# sensor.temperature()
# sensor.humidity()
DIGITS = [ #7-segment numbers
"11111100", "01100000", "11011010", #0,1,2
"11110010", "01100110", "10110110", #3,4,5
"10111110", "11100000", "11111110", #6,7,8
"11100110", #9
]
hum = 0
current = -1
def dataInputSevenSegment(dataPin,latchPin,digitIndex):
x = range(7,-1,-1)
for index in x:
clockPin.value(0)
if DIGITS[digitIndex][index] == "1":
dataPin.value(1)
else:
dataPin.value(0)
clockPin.value(1)
clockPin.value(0)
latchPin.value(1)
clockPin.value(1)
latchPin.value(0)
while True:
# Read humidity sensor value
sensor.measure()
hum = sensor.humidity()
strHum = str(f'{hum:.0f}')
#print humidity value
print("\r \r", end="")
print("Humidity: " + strHum + "%", end="")
if len(strHum) < 2:
strHum = "0" + strHum
dataInputSevenSegment(DATAPINS[0], LATCHPINS[0], int(strHum[0]))
dataInputSevenSegment(DATAPINS[1], LATCHPINS[1], int(strHum[1]))
sleep(1)