enfancify demo

This commit is contained in:
Owen 2024-10-14 12:04:01 +02:00
parent 454de66351
commit c0d10677aa

View File

@ -38,15 +38,20 @@ def read_sensor():
p = round(bme280.get_pressure()) p = round(bme280.get_pressure())
return t, h, p return t, h, p
# initial reading settles sensor def show_text(s, x, y):
with canvas(device) as draw:
draw.rectangle(device.bounding_box, outline="white", fill="black")
draw.text((x, y), s, fill="white")
# initial reading to settle sensor
_, _, _ = read_sensor() _, _, _ = read_sensor()
show_text('Initialising..', 36, 26)
print('Initialising')
# loop # loop
while True: while True:
sleep(1) sleep(1)
temp, humi, pres = read_sensor() temp, humi, pres = read_sensor()
out = ' Temp: {}°C\n Humi: {}%\n Pres: {}mb'.format(temp, humi, pres) out = ' Temp: {}°C\n Humi: {}%\n Pres: {}mb'.format(temp, humi, pres)
with canvas(device) as draw: show_text(out, 26, 12)
draw.rectangle(device.bounding_box, outline="white", fill="black")
draw.text((26, 12), out, fill="white")
print('{} :: {}°C, {}%, {}mb'.format(ctime(),temp, humi, pres)) print('{} :: {}°C, {}%, {}mb'.format(ctime(),temp, humi, pres))