from utime import sleep
from neopixel import NeoPixel
from random import randrange
import dht
from machine import Pin
print("started")
NUM_LEDS1 = 16
NUM_LEDS2 = 16
NUM_LEDS = NUM_LEDS1 + NUM_LEDS2
st = 0.5
leds = NeoPixel(Pin(15, Pin.OUT),NUM_LEDS)
temp_sens = dht.DHT22(Pin(13))
def convert(x, in_max, out_max, in_min = 0, out_min = 0):
return (x - in_min) * (out_max - out_min) // (in_max - in_min) + out_min
def turn_off(NUM_LED):
for i in range(NUM_LED):
leds[i] = 0,0,0
for i in range(NUM_LEDS1):
print(i, convert(700, 4096, NUM_LEDS1))
while True:
temp_sens.measure()
humidity = int(temp_sens.humidity())
temp = int(temp_sens.temperature())
# wet
redSteps = convert(humidity, 100, NUM_LEDS1 )
for i in range(redSteps ):
leds[i] = [255, convert(i, NUM_LEDS1, 255), 0]
for x in range(NUM_LEDS1 - redSteps):
leds[NUM_LEDS1 - x -1] = [convert(x, NUM_LEDS1, 255), 255, 0]
# temp
redSteps = convert(temp, 80, NUM_LEDS2, -40 )
for i in range(NUM_LEDS1, redSteps + NUM_LEDS2 ):
leds[i] = [255, convert(i, NUM_LEDS2, 255), 0]
for x in range(NUM_LEDS1, NUM_LEDS2 - redSteps + NUM_LEDS2):
leds[NUM_LEDS2 - x -1] = [convert(x, NUM_LEDS2, 255), 255, 0]
leds.write()
turn_off(NUM_LEDS)