|
| 1 | +# SPDX-FileCopyrightText: 2024 |
| 2 | +# SPDX-License-Identifier: MIT |
| 3 | + |
| 4 | +import board |
| 5 | +from adafruit_display_text.label import Label |
| 6 | +from displayio import Group |
| 7 | +from terminalio import FONT |
| 8 | + |
| 9 | +import adafruit_ds3231 |
| 10 | + |
| 11 | +# Create the RTC object, communicating over the board's default I2C bus |
| 12 | +i2c = board.I2C() # uses board.SCL and board.SDA |
| 13 | +# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector |
| 14 | +ds3231 = adafruit_ds3231.DS3231(i2c) |
| 15 | + |
| 16 | + |
| 17 | +# Example written for boards with built-in displays |
| 18 | +display = board.DISPLAY |
| 19 | + |
| 20 | +# Create a main_group to hold anything we want to show on the display. |
| 21 | +main_group = Group() |
| 22 | + |
| 23 | +# Create a Label to show the readings. If you have a very small |
| 24 | +# display you may need to change to scale=1. |
| 25 | +display_output_label = Label(FONT, text="", scale=2) |
| 26 | + |
| 27 | +# Place the label near the top left corner with anchored positioning |
| 28 | +display_output_label.anchor_point = (0, 0) |
| 29 | +display_output_label.anchored_position = (4, 4) |
| 30 | + |
| 31 | +# Add the label to the main_group |
| 32 | +main_group.append(display_output_label) |
| 33 | + |
| 34 | +# Set the main_group as the root_group of the display |
| 35 | +display.root_group = main_group |
| 36 | + |
| 37 | + |
| 38 | +# Lookup tables for names of days and months - pretty printing |
| 39 | +days = ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday") |
| 40 | +months = ( |
| 41 | + "January", |
| 42 | + "February", |
| 43 | + "March", |
| 44 | + "April", |
| 45 | + "May", |
| 46 | + "June", |
| 47 | + "July", |
| 48 | + "August", |
| 49 | + "September", |
| 50 | + "October", |
| 51 | + "November", |
| 52 | + "December", |
| 53 | +) |
| 54 | + |
| 55 | +# Begin main loop |
| 56 | +while True: |
| 57 | + t = ds3231.datetime |
| 58 | + # Update the label.text property to change the text on the display |
| 59 | + display_output_label.text = f"{days[t.tm_wday]}\ |
| 60 | + \n{t.tm_mday} {months[t.tm_mon-1]} {t.tm_year}\ |
| 61 | + \n{t.tm_hour}:{t.tm_min:02}:{t.tm_sec:02}" |
0 commit comments