|
| 1 | +# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries |
| 2 | +# SPDX-FileCopyrightText: 2025 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_ltr390 |
| 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 | +ltr = adafruit_ltr390.LTR390(i2c) |
| 19 | + |
| 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_light = Label(FONT, text="", scale=2) |
| 24 | +display_output_lux = Label(FONT, text="", scale=2) |
| 25 | + |
| 26 | +# place the label(s) in the middle of the screen with anchored positioning |
| 27 | +display_output_light.anchor_point = (0, 0) |
| 28 | +display_output_light.anchored_position = ( |
| 29 | + 4, |
| 30 | + board.DISPLAY.height // 2 - 60, |
| 31 | +) |
| 32 | +display_output_lux.anchor_point = (0, 0) |
| 33 | +display_output_lux.anchored_position = ( |
| 34 | + 4, |
| 35 | + board.DISPLAY.height // 2 - 40, |
| 36 | +) |
| 37 | + |
| 38 | +# add the label(s) to the main_group |
| 39 | +main_group.append(display_output_light) |
| 40 | +main_group.append(display_output_lux) |
| 41 | + |
| 42 | +# set the main_group as the root_group of the built-in DISPLAY |
| 43 | +board.DISPLAY.root_group = main_group |
| 44 | + |
| 45 | +# begin main loop |
| 46 | +while True: |
| 47 | + # update the text of the label(s) to show the sensor readings |
| 48 | + display_output_light.text = f"Ambient Light: {ltr.light:.2f}" |
| 49 | + display_output_lux.text = f"Lux: {ltr.lux:.2f}" |
| 50 | + # wait for a bit |
| 51 | + time.sleep(0.5) |
0 commit comments