From 633d1ba0dc6fc5eb3c319a14a8e88e925bc7e3d5 Mon Sep 17 00:00:00 2001 From: benevpi <31006592+benevpi@users.noreply.github.com> Date: Tue, 19 Jan 2021 17:14:12 +0000 Subject: [PATCH] Create thermometer.py --- examples/thermometer.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 examples/thermometer.py diff --git a/examples/thermometer.py b/examples/thermometer.py new file mode 100644 index 0000000..e845c06 --- /dev/null +++ b/examples/thermometer.py @@ -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) + \ No newline at end of file