From f3d5a52a2cf2aa46b733abb8a326d67f22705407 Mon Sep 17 00:00:00 2001 From: snkYmkrct Date: Thu, 3 Oct 2024 13:25:54 +0200 Subject: [PATCH 1/3] Add displayio example --- examples/ds3231_displayio_simpletest.py | 50 +++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 examples/ds3231_displayio_simpletest.py diff --git a/examples/ds3231_displayio_simpletest.py b/examples/ds3231_displayio_simpletest.py new file mode 100644 index 0000000..a60a24e --- /dev/null +++ b/examples/ds3231_displayio_simpletest.py @@ -0,0 +1,50 @@ +# SPDX-FileCopyrightText: 2024 +# SPDX-License-Identifier: MIT + +import board +from adafruit_display_text.label import Label +from displayio import Group +from terminalio import FONT + +import adafruit_ds3231 + +# Create the RTC object, communicating over the board's default I2C bus +i2c = board.I2C() # uses board.SCL and board.SDA +# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector +ds3231 = adafruit_ds3231.DS3231(i2c) + + +# Example written for boards with built-in displays +display = board.DISPLAY + +# Create a main_group to hold anything we want to show on the display. +main_group = Group() + +# Create a Label to show the readings. If you have a very small +# display you may need to change to scale=1. +display_output_label = Label(FONT, text="", scale=2) + +# Place the label near the top left corner with anchored positioning +display_output_label.anchor_point = (0, 0) +display_output_label.anchored_position = (4, 4) + +# Add the label to the main_group +main_group.append(display_output_label) + +# Set the main_group as the root_group of the display +display.root_group = main_group + + +# Lookup tables for names of days and months - pretty printing +days = ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", + "Saturday", "Sunday") +months = ("January", "February", "March", "April", "May", "June", + "July", "August", "September", "October", "November", "December") + +# Begin main loop +while True: + t = ds3231.datetime + # Update the label.text property to change the text on the display + display_output_label.text = f"{days[t.tm_wday]}\ + \n{t.tm_mday} {months[t.tm_mon]} {t.tm_year}\ + \n{t.tm_hour}:{t.tm_min:02}:{t.tm_sec:02}" From 29557286ec3548db8ce83756d6a3791ac2bd553c Mon Sep 17 00:00:00 2001 From: snkYmkrct Date: Thu, 3 Oct 2024 13:27:01 +0200 Subject: [PATCH 2/3] Fix black error --- examples/ds3231_displayio_simpletest.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/examples/ds3231_displayio_simpletest.py b/examples/ds3231_displayio_simpletest.py index a60a24e..3e84b6c 100644 --- a/examples/ds3231_displayio_simpletest.py +++ b/examples/ds3231_displayio_simpletest.py @@ -36,10 +36,21 @@ # Lookup tables for names of days and months - pretty printing -days = ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", - "Saturday", "Sunday") -months = ("January", "February", "March", "April", "May", "June", - "July", "August", "September", "October", "November", "December") +days = ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday") +months = ( + "January", + "February", + "March", + "April", + "May", + "June", + "July", + "August", + "September", + "October", + "November", + "December", +) # Begin main loop while True: From f34ac81e2b9fe4527ec33fd16630a1fb4c497db9 Mon Sep 17 00:00:00 2001 From: snkYmkrct Date: Thu, 3 Oct 2024 17:22:57 +0200 Subject: [PATCH 3/3] Fix value range --- examples/ds3231_displayio_simpletest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/ds3231_displayio_simpletest.py b/examples/ds3231_displayio_simpletest.py index 3e84b6c..37e804a 100644 --- a/examples/ds3231_displayio_simpletest.py +++ b/examples/ds3231_displayio_simpletest.py @@ -57,5 +57,5 @@ t = ds3231.datetime # Update the label.text property to change the text on the display display_output_label.text = f"{days[t.tm_wday]}\ - \n{t.tm_mday} {months[t.tm_mon]} {t.tm_year}\ + \n{t.tm_mday} {months[t.tm_mon-1]} {t.tm_year}\ \n{t.tm_hour}:{t.tm_min:02}:{t.tm_sec:02}"