|
| 1 | +# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries |
| 2 | +# SPDX-FileCopyrightText: 2024 Jose D. Montoya |
| 3 | +# |
| 4 | +# SPDX-License-Identifier: MIT |
| 5 | + |
| 6 | +import time |
| 7 | +import board |
| 8 | +from adafruit_display_text.bitmap_label import Label |
| 9 | +from terminalio import FONT |
| 10 | +from displayio import Group |
| 11 | +import adafruit_adt7410 |
| 12 | + |
| 13 | +# Simple demo of using the built-in display. |
| 14 | +# create a main_group to hold anything we want to show on the display. |
| 15 | +main_group = Group() |
| 16 | +# Initialize I2C bus and sensor. |
| 17 | +i2c = board.I2C() # uses board.SCL and board.SDA |
| 18 | +adt = adafruit_adt7410.ADT7410(i2c, address=0x48) |
| 19 | +adt.high_resolution = True |
| 20 | + |
| 21 | +# Create Label(s) to show the readings. If you have a very small |
| 22 | +# display you may need to change to scale=1. |
| 23 | +display_output_label = Label(FONT, text="", scale=2) |
| 24 | + |
| 25 | +# place the label(s) in the middle of the screen with anchored positioning |
| 26 | +display_output_label.anchor_point = (0, 0) |
| 27 | +display_output_label.anchored_position = ( |
| 28 | + 4, |
| 29 | + board.DISPLAY.height // 2 - 60, |
| 30 | +) |
| 31 | + |
| 32 | +# add the label(s) to the main_group |
| 33 | +main_group.append(display_output_label) |
| 34 | + |
| 35 | +# set the main_group as the root_group of the built-in DISPLAY |
| 36 | +board.DISPLAY.root_group = main_group |
| 37 | + |
| 38 | +# begin main loop |
| 39 | +while True: |
| 40 | + # update the text of the label(s) to show the sensor readings |
| 41 | + display_output_label.text = f"Temperature: {adt.temperature:.1f} C" |
| 42 | + # wait for a bit |
| 43 | + time.sleep(0.5) |
0 commit comments