Create thermometer.py

main
benevpi 2021-01-19 17:14:12 +00:00
rodzic dfcff37417
commit 633d1ba0dc
1 zmienionych plików z 26 dodań i 0 usunięć

Wyświetl plik

@ -0,0 +1,26 @@
import machine
import time
from ws2812b import ws2812b
num_leds = 30
pixels = ws2812b(num_leds, 0,0)
sensor_temp = machine.ADC(4)
conversion_factor = 3.3 / 65535
min_temp = 0
max_temp = 30
while True:
reading = sensor_temp.read_u16() * conversion_factor
temperature = 27 - (reading - 0.706)/0.001721
temp_int = int(temperature)
for i in range(num_leds):
if i < temp_int:
pixels.set_pixel(i, 10,0,0)
else:
pixels.set_pixel(i,0,0,0)
pixels.show()
time.sleep(2)