|
| 1 | +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries |
| 2 | +# SPDX-FileCopyrightText: Copyright (c) 2021 Melissa LeBlanc-Williams for Adafruit Industries |
| 3 | +# |
| 4 | +# SPDX-License-Identifier: MIT |
| 5 | +""" |
| 6 | +This example demonstrates how to log temperature on the FunHouse. Due to the sensors being near the |
| 7 | +power supply, usage of peripherals generates extra heat. By turning off unused peripherals and back |
| 8 | +on only during usage, it can lower the heat. Using light sleep in between readings will also help. |
| 9 | +By using an offset, we can improve the accuracy even more. Improving airflow near the FunHouse will |
| 10 | +also help. |
| 11 | +""" |
| 12 | + |
| 13 | +from adafruit_funhouse import FunHouse |
| 14 | + |
| 15 | +funhouse = FunHouse(default_bg=None) |
| 16 | + |
| 17 | +DELAY = 180 |
| 18 | +FEED = "temperature" |
| 19 | +TEMPERATURE_OFFSET = ( |
| 20 | + 3 # Degrees C to adjust the temperature to compensate for board produced heat |
| 21 | +) |
| 22 | + |
| 23 | +# Turn things off |
| 24 | +funhouse.peripherals.dotstars.fill(0) |
| 25 | +funhouse.display.brightness = 0 |
| 26 | +funhouse.network.enabled = False |
| 27 | + |
| 28 | + |
| 29 | +def log_data(): |
| 30 | + print("Logging Temperature") |
| 31 | + print("Temperature %0.1F" % (funhouse.peripherals.temperature - TEMPERATURE_OFFSET)) |
| 32 | + # Turn on WiFi |
| 33 | + funhouse.network.enabled = True |
| 34 | + # Connect to WiFi |
| 35 | + funhouse.network.connect() |
| 36 | + # Push to IO using REST |
| 37 | + funhouse.push_to_io(FEED, funhouse.peripherals.temperature - TEMPERATURE_OFFSET) |
| 38 | + # Turn off WiFi |
| 39 | + funhouse.network.enabled = False |
| 40 | + |
| 41 | + |
| 42 | +while True: |
| 43 | + log_data() |
| 44 | + print("Sleeping for {} seconds...".format(DELAY)) |
| 45 | + funhouse.enter_light_sleep(DELAY) |
0 commit comments