Add multi-panel Pico UDP firmware and Python LED control.
Pico panels get static IPs on 10.1.1.10–14 with per-panel LED counts, Makefile deploy targets, and Python examples for animations, sync tests, and direct Pi SPI control. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
79
examples/matrix_demo.py
Executable file
79
examples/matrix_demo.py
Executable file
@@ -0,0 +1,79 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Rainbow scroll on the LED matrix (local SPI or Pico panel)."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
|
||||
from leds import ANIMATIONS, LedMatrix
|
||||
from leds.array_config import MATRIX_BRIGHTNESS, MATRIX_HEIGHT, MATRIX_SPI_BUS, MATRIX_SPI_DEVICE, MATRIX_WIDTH
|
||||
from leds.config import spi_strip_config
|
||||
from leds.panel_udp import (
|
||||
add_panel_network_args,
|
||||
format_panel_targets,
|
||||
panel_targets_from_args,
|
||||
run_panel_animation_loop,
|
||||
)
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(description="LED matrix rainbow demo")
|
||||
parser.add_argument("--brightness", type=float, default=MATRIX_BRIGHTNESS)
|
||||
parser.add_argument(
|
||||
"--spi-bus",
|
||||
type=int,
|
||||
default=int(os.environ.get("PORTAL_SPI_BUS", MATRIX_SPI_BUS)),
|
||||
)
|
||||
parser.add_argument("--spi-device", type=int, default=MATRIX_SPI_DEVICE)
|
||||
parser.add_argument("--panel", action="store_true", help="send to Pico panel(s) over UDP")
|
||||
add_panel_network_args(parser)
|
||||
args = parser.parse_args()
|
||||
|
||||
print(f"Matrix: {MATRIX_WIDTH}×{MATRIX_HEIGHT} ({MATRIX_WIDTH * MATRIX_HEIGHT} LEDs)")
|
||||
|
||||
if args.panel:
|
||||
targets = panel_targets_from_args(args)
|
||||
try:
|
||||
run_panel_animation_loop(
|
||||
targets,
|
||||
args.port,
|
||||
"rainbow",
|
||||
brightness=args.brightness,
|
||||
)
|
||||
except KeyboardInterrupt:
|
||||
print("\nStopped.")
|
||||
except OSError as exc:
|
||||
print(f"Network error: {exc}", file=sys.stderr)
|
||||
return 1
|
||||
return 0
|
||||
|
||||
draw = ANIMATIONS["rainbow"]
|
||||
cfg = spi_strip_config(
|
||||
MATRIX_WIDTH * MATRIX_HEIGHT,
|
||||
spi_bus=args.spi_bus,
|
||||
spi_device=args.spi_device,
|
||||
brightness=args.brightness,
|
||||
)
|
||||
|
||||
try:
|
||||
with LedMatrix(config0=cfg) as matrix:
|
||||
frame = 0
|
||||
while True:
|
||||
draw(matrix, frame)
|
||||
matrix.show()
|
||||
frame += 1
|
||||
time.sleep(1 / 30)
|
||||
except KeyboardInterrupt:
|
||||
print("\nStopped.")
|
||||
return 0
|
||||
except Exception as exc:
|
||||
print(f"Error: {exc}", file=sys.stderr)
|
||||
print("Try: --panel --host <pico-ip>", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user