mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-16 07:03:00 +00:00
Add ChuckBuilds.py test screen
This commit is contained in:
74
ChuckBuilds.py
Normal file
74
ChuckBuilds.py
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import time
|
||||||
|
import sys
|
||||||
|
from rgbmatrix import RGBMatrix, RGBMatrixOptions
|
||||||
|
from PIL import Image, ImageDraw, ImageFont
|
||||||
|
|
||||||
|
def main():
|
||||||
|
# Matrix configuration
|
||||||
|
options = RGBMatrixOptions()
|
||||||
|
options.rows = 32
|
||||||
|
options.cols = 64
|
||||||
|
options.chain_length = 2
|
||||||
|
options.parallel = 1
|
||||||
|
options.hardware_mapping = 'adafruit-hat-pwm'
|
||||||
|
options.brightness = 90
|
||||||
|
options.pwm_bits = 10
|
||||||
|
options.pwm_lsb_nanoseconds = 150
|
||||||
|
options.led_rgb_sequence = 'RGB'
|
||||||
|
options.pixel_mapper_config = ''
|
||||||
|
options.row_address_type = 0
|
||||||
|
options.multiplexing = 0
|
||||||
|
options.disable_hardware_pulsing = False
|
||||||
|
options.show_refresh_rate = False
|
||||||
|
options.limit_refresh_rate_hz = 90
|
||||||
|
options.gpio_slowdown = 2
|
||||||
|
|
||||||
|
# Initialize the matrix
|
||||||
|
matrix = RGBMatrix(options=options)
|
||||||
|
canvas = matrix.CreateFrameCanvas()
|
||||||
|
|
||||||
|
# Load the PressStart2P font
|
||||||
|
font_path = "assets/fonts/PressStart2P-Regular.ttf"
|
||||||
|
font_size = 1
|
||||||
|
font = ImageFont.truetype(font_path, font_size)
|
||||||
|
|
||||||
|
# Create a PIL image and drawing context
|
||||||
|
image = Image.new('RGB', (matrix.width, matrix.height))
|
||||||
|
draw = ImageDraw.Draw(image)
|
||||||
|
|
||||||
|
# Text to display
|
||||||
|
text = " Chuck Builds"
|
||||||
|
|
||||||
|
# Find the largest font size that fits
|
||||||
|
while True:
|
||||||
|
bbox = draw.textbbox((0, 0), text, font=font)
|
||||||
|
text_width = bbox[2] - bbox[0]
|
||||||
|
text_height = bbox[3] - bbox[1]
|
||||||
|
if text_width > matrix.width or text_height > matrix.height:
|
||||||
|
font_size -= 1
|
||||||
|
font = ImageFont.truetype(font_path, font_size)
|
||||||
|
break
|
||||||
|
font_size += 1
|
||||||
|
|
||||||
|
# Center the text
|
||||||
|
x = (matrix.width - text_width) // 2
|
||||||
|
y = (matrix.height - text_height) // 2
|
||||||
|
|
||||||
|
# Draw the text
|
||||||
|
draw.text((x, y), text, font=font, fill=(255, 255, 255))
|
||||||
|
|
||||||
|
# Display the image
|
||||||
|
canvas.SetImage(image)
|
||||||
|
matrix.SwapOnVSync(canvas)
|
||||||
|
|
||||||
|
# Keep the script running
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
time.sleep(1)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
matrix.Clear()
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Reference in New Issue
Block a user