import dht
import neopixel
from machine import Pin, ADC, PWM
from time import sleep
from random import randrange as r
from random import randint
num_led= 0.1
# gumb začne
NUM_LED = 24
leds = neopixel.NeoPixel(Pin(15), NUM_LED)
l = NUM_LED // 4
color = [0, 0, 255]
ran = [r(0,255),r(0,255),r(0,255)]
btn = Pin(19, Pin.IN, Pin.PULL_UP)
button_pressed = True
sense = dht.DHT22(Pin(2))
def convert(x, in_min, in_max, out_min, out_max):
return (x - in_min) * (out_max - out_min) // (in_max - in_min) + out_min
nl = 16
g = r(6)
for d in range(1):
print(d, convert(d, 0, 4096, 0, 16))
nll = 32
leds2 = neopixel.NeoPixel(Pin(18), nll)
sense = dht.DHT22(Pin(2))
while True:
btnVal = not bool(btn.value())
if btnVal and button_pressed:
for četrtina in range(4):
color = [0, 0, 0]
if četrtina == 0:
color = ran
sleep(num_led)
leds.write()
ran = [r(0,255),r(0,255),r(0,255)]
elif četrtina == 1:
color = ran
sleep(num_led)
leds.write()
ran = [r(0,255),r(0,255),r(0,255)]
elif četrtina == 2:
color = ran
sleep(num_led)
leds.write()
ran = [r(0,255),r(0,255),r(0,255)]
elif četrtina == 3:
color = ran
sleep(num_led)
leds.write()
ran = [r(0,255),r(0,255),r(0,255)]
for i in range(četrtina * l, (četrtina + 1) * l):
leds[i] = color
sleep(num_led)
leds.write()
ran = [r(0,255),r(0,255),r(0,255)]
for i in range(četrtina * l, (četrtina + 1) * l):
leds[i] = [0, 0, 0]
sleep(num_led)
leds.write()
ran = [r(0,255),r(0,255),r(0,255)]
sleep(0.1)
print(btnVal)
pot = ADC(Pin(4))
num_led=convert(pot.read(),0,4095,0.2,1)
print(num_led)
sense.measure()
hum = sense.humidity()
temp=sense.temperature()
print(sense.humidity(), sense.temperature())
h = convert(hum, 0,100,0,10)
t = convert(temp,0,80,0,10)
for c in range(nl):
leds2[c]=([0,0,25*int(h)])
leds2.write()
if c>=16:
leds2[c]=([25*int(t),0,0])
leds2.write()