from machine import Pin, Timer
from dht import DHT22
from time import sleep 
import utime
import time
tim = Timer
sensor = DHT22(Pin(21))
led_list = [23,22,19,18,5,17,16,4,0,2]
n=0
for pin_num in led_list:
  led_list[n] = Pin(pin_num, Pin.OUT)
  n+=1   
def LedSegOut(array):
  for x in range(10): led_list[x].value(not(array[x]))
def LedSegCycle():
  array = [0,0,0,0,0,0,0,0,0,1]
  while True:
    array = array[1:]+array[:1]
    LedSegOut(array)
    utime.sleep(0.05)
def LedSegPerc(n):
  thresholds=[100,80,70,60,50,40,30,20]
  array=list(map(lambda x: (1,0)[x>n],thresholds))
  LedSegOut(array)
while True:
   # LedSegOut([0,0,0,0,0,1,1,1,1,1])
   LedSegCycle()
   # LedSegPerc(82)
while True:
  try:
    sleep(2)
    sensor.measure()
    temp = sensor.temperature()
    hum = sensor.humidity()
    temp_f = temp * (9/5) + 32.0
    print('Temperature: %3.1f C' %temp)
    print('Temperature: %3.1f F' %temp_f)
    print('Humidity: %3.1f %%' %hum)
  except OSError as e:
    print('Failed to read sensor.')