aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorD Delmar Davis <don@suspectdevices.com>2025-06-22 09:47:57 -0700
committerD Delmar Davis <don@suspectdevices.com>2025-06-22 09:47:57 -0700
commitf7172dbb6438cb60cc781377410f9b6ac6a6250f (patch)
tree7f367e9db215d12b1cd28cc554c9dbe230cb0086 /bin
parent084f7f30c631c5b7ce50db2ba58cd9926d6a84ab (diff)
getting the board right
Diffstat (limited to 'bin')
-rw-r--r--bin/timetemp.py82
1 files changed, 44 insertions, 38 deletions
diff --git a/bin/timetemp.py b/bin/timetemp.py
index 5bb6bf3..39791d2 100644
--- a/bin/timetemp.py
+++ b/bin/timetemp.py
@@ -1,40 +1,46 @@
-#!/usr/bin/python
+# SPDX-FileCopyrightText: 2019 Mikey Sklar for Adafruit Industries
+#
+# SPDX-License-Identifier: MIT
import time
-import datetime
-
-from Adafruit_LED_Backpack import SevenSegment
-
-# ===========================================================================
-# Clock Example
-# ===========================================================================
-segment = SevenSegment.SevenSegment(address=0x70)
-
-# Initialize the display. Must be called once before using the display.
-segment.begin()
-
-print "Press CTRL+Z to exit"
-
-# Continually update the time on a 4 char, 7-segment display
-while(True):
- now = datetime.datetime.now()
- hour = now.hour
- minute = now.minute
- second = now.second
-
- segment.clear()
- # Set hours
- segment.set_digit(0, int(hour / 10)) # Tens
- segment.set_digit(1, hour % 10) # Ones
- # Set minutes
- segment.set_digit(2, int(minute / 10)) # Tens
- segment.set_digit(3, minute % 10) # Ones
- # Toggle colon
- segment.set_colon(second % 2) # Toggle colon at 1Hz
-
- # Write the display buffer to the hardware. This must be called to
- # update the actual display LEDs.
- segment.write_display()
-
- # Wait a quarter second (less than 1 second to prevent colon blinking getting$
- time.sleep(0.25) \ No newline at end of file
+import board
+import busio
+from adafruit_ht16k33 import segments
+
+# Create the I2C interface.
+i2c = busio.I2C(board.SCL, board.SDA)
+
+# Create the LED segment class.
+# This creates a 7 segment 4 character display:
+display = segments.Seg7x4(i2c)
+
+# Clear the display.
+display.fill(0)
+
+# Can just print a number
+display.print(42)
+time.sleep(1)
+
+# Set the first character to '1':
+display[0] = '1'
+# Set the second character to '2':
+display[1] = '2'
+# Set the third character to 'A':
+display[2] = 'A'
+# Set the forth character to 'B':
+display[3] = 'B'
+time.sleep(1)
+
+numbers = [0.0, 1.0, 0.55, 10.23, 100.5]
+
+# print floating point numbers
+for i in numbers:
+ display.print(str(i))
+ time.sleep(0.5)
+
+# print hex values, enable colon
+for i in range(0xFF):
+ display.fill(0)
+ display.print(':')
+ display.print(hex(i))
+ time.sleep(0.25)