|
| 1 | +# SPDX-FileCopyrightText: 2024 |
| 2 | +# SPDX-License-Identifier: MIT |
| 3 | + |
| 4 | +import time |
| 5 | +import board |
| 6 | +from adafruit_display_text.bitmap_label import Label |
| 7 | +from displayio import Group |
| 8 | +from terminalio import FONT |
| 9 | + |
| 10 | +import adafruit_vcnl4040 |
| 11 | + |
| 12 | +# Create sensor object, communicating over the board's default I2C bus |
| 13 | +i2c = board.I2C() # uses board.SCL and board.SDA |
| 14 | +# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector |
| 15 | +vcnl4040 = adafruit_vcnl4040.VCNL4040(i2c) |
| 16 | + |
| 17 | + |
| 18 | +# Example written for boards with built-in displays |
| 19 | +display = board.DISPLAY |
| 20 | + |
| 21 | +# Create a main_group to hold anything we want to show on the display. |
| 22 | +main_group = Group() |
| 23 | + |
| 24 | +# Create a Label to show the readings. If you have a very small |
| 25 | +# display you may need to change to scale=1. |
| 26 | +display_output_label = Label(FONT, text="", scale=2) |
| 27 | + |
| 28 | +# Place the label near the top left corner with anchored positioning |
| 29 | +display_output_label.anchor_point = (0, 0) |
| 30 | +display_output_label.anchored_position = (4, 4) |
| 31 | + |
| 32 | +# Add the label to the main_group |
| 33 | +main_group.append(display_output_label) |
| 34 | + |
| 35 | +# Set the main_group as the root_group of the display |
| 36 | +display.root_group = main_group |
| 37 | + |
| 38 | +# Begin main loop |
| 39 | +while True: |
| 40 | + # Update the label.text property to change the text on the display |
| 41 | + display_output_label.text = f"Proximity: {vcnl4040.proximity} \ |
| 42 | + \nLight: {vcnl4040.lux:.1f} lux \ |
| 43 | + \nWhite: {vcnl4040.white:.1f}" |
| 44 | + # Wait a bit between reads |
| 45 | + time.sleep(0.5) |
0 commit comments