import dht
import neopixel
from machine import Pin, ADC
from time import sleep
from random import randrange as r
def convert(x, in_min, in_max, out_min, out_max):
return (x - in_min) * (out_max - out_min)
button1 = Pin(27, Pin.IN, Pin.PULL_UP)
button2 = Pin(26, Pin.IN, Pin.PULL_UP)
nl = 160
leds = neopixel.NeoPixel(Pin(13), nl)
d=0.007
pot1 = ADC(Pin(14))
pressed1 = True
pressed2 = True
sense = dht.DHT22(Pin(4))
while True:
a=100
b=100
c=100
col4 = [r(100,255),r(100,255),r(100,255)]
if not button1.value():
if pressed1:
pressed1 = False
for l in range(nl):
sense.measure()
print(sense.humidity(), sense.temperature())
h = convert(sense.humidity(), 0,100,0,10)
t = convert(sense.temperature(),0,80,0,10)
spanje1 = (pot1.read())/10000
leds[l]= ([25*int(t),0,0])
sleep(spanje1)
if l>=64:
leds[l]= ([0,0,25*int(h)])
sleep(d*6)
if l>=112:
col3 = [a,b,c]
leds[l]=col3
sleep(d*9)
a+=10
b+=10
c+=10
if a>=255:
a=100
elif b>=255:
b=100
elif c>=255:
c=100
if l>=144:
leds[l]=col4
sleep(d*12)
leds.write()
if not button2.value():
if pressed2:
pressed2 = False
leds.fill([0,0,0])
else:
pressed2=True
else:
pressed1=True