To use pypixelcolor as a library, import the necessary clients and models from pypixelcolor or pypixelcolor.models. The library uses a context manager pattern for the Client class to ensure connections to the LED matrix are automatically opened and closed.
Common tasks include:
- Inspecting device dimensions via
get_device_info(). - Displaying images or GIFs using
send_image() with a ResizeMethod. - Sending text with
send_text(), supporting animations, emojis, and inline color tags (e.g., [#ff0000]text[/]). - Using custom fonts via
FontConfig.from_file(). - Controlling timers with
set_timer() and TimerAction. - Adjusting brightness and clock modes.
import time
from pypixelcolor import (
Client,
TextAnimation,
TimerAction,
ResizeMethod,
FontConfig,
)
MAC_ADDRESS = "30:E1:AF:BD:5F:D0"
# The context manager automatically handles connection and disconnection
with Client(MAC_ADDRESS) as device:
# 1. Inspect device dimensions and info
info = device.get_device_info()
print(f"Connected to {info.width}x{info.height} LED matrix (Type {info.led_type})")
# 2. Display an image or animated GIF
device.send_image("./banner.png", resize_method=ResizeMethod.FIT)
time.sleep(3)
# 3. Send text with animations, emojis, and inline color tags
device.send_text(
"[#ff0000]Hello[/] [#00ff00]pypixelcolor[/] 🚀",
animation=TextAnimation.SCROLL_LEFT,
speed=80,
)
time.sleep(3)
# 4. Smooth pulsing text with a custom font
custom_font = FontConfig.from_file("./fonts/retro.ttf", font_size=16)
device.send_text("ALERT", font=custom_font, animation=TextAnimation.FADE)
time.sleep(2)
# 5. Control stopwatch timer
device.set_timer(TimerAction.START)
time.sleep(5)
device.set_timer(TimerAction.STOP)
# 6. Clock mode and brightness
device.set_brightness(60)
device.set_clock_mode(style=1, format_24=True)