import dht
from machine import Pin, ADC
from neopixel import NeoPixel
from time import sleep
NUM_LEDS = 16
current_led = 0
direction = 1
pixels = NeoPixel(Pin(15), NUM_LEDS)
gumb = Pin(4, Pin.IN, Pin.PULL_UP)
sense = dht.DHT22(Pin(5))
pot = ADC(Pin(13))
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
def read_sensors():
sense.measure()
tempe = sense.temperature()
color = convert(tempe, -40, 80, 50, 255)
return (int(color), 0, 0)
def read_potentiometer():
pot_value = pot.read()
speed = convert(pot_value, 0, 4095, 0.05, 1) #(0.05 do 1 sekunda) spremeni pot
return speed
def main():
global current_led, direction
pixels[current_led] = read_sensors()
pixels.write()
while True:
if gumb.value() == 1:
pixels[current_led] = (0, 0, 0)
current_led += direction
if current_led == NUM_LEDS:
current_led = NUM_LEDS - 1
direction = -1
elif current_led == -1:
current_led = 0
direction = 1
color = read_sensors()
pixels[current_led] = color
pixels.write()
debounce_time = read_potentiometer()
sleep(debounce_time)
sleep(0.01)
main()