from machine import Pin from neopixel import NeoPixel from time import sleep_ms from onewire import OneWire from ds18x20 import DS18X20 def main(): # init buttons button1 = Pin(18,Pin.IN,Pin.PULL_DOWN) button2 = Pin(19,Pin.IN,Pin.PULL_DOWN) # init leds leds = [] for i in range(0,6): leds.append(Pin(2+i,Pin.OUT)) # init neopixel pin = Pin(16,Pin.OUT) pin.off() sleep_ms(2000) pin.on() pixel = NeoPixel(pin,1) pixel[0] = (0,0,0) pixel.write() # init onewire tempsensor temp = DS18X20(OneWire(Pin(17))) sensors = temp.scan() # program while True: if button1.value(): for led in leds: led.on() sleep_ms(100) elif button2.value(): for led in leds: led.off() sleep_ms(100) else: for sensor in sensors: temp.convert_temp() value = temp.read_temp(sensor) print(f"Temperature: {round(value,2)}°C") if value >= 35.0: pixel[0] = (0,255,0) pixel.write() elif value < 35.0 and value >= 30.0: pixel[0] = (255,255,0) pixel.write() else: pixel[0] = (255,0,0) pixel.write() sleep_ms(1000) if __name__ == "__main__": main()