Last active
April 21, 2023 22:22
-
-
Save dgrnbrg/413f05c906f5b504c622876753012cd2 to your computer and use it in GitHub Desktop.
e131/sacn/artnet test program
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
####### | |
####### In your python env, make sure you've installed pyartnet (`pip install pyartnet`) | |
####### | |
####### To run, you do: `python3 artnet.py` or `python3 artnet.py 2` | |
####### The numeric argument is the index of the pixel's color channel that we're animating | |
####### | |
import asyncio | |
import logging | |
from pyartnet import SacnNode, ArtNetNode | |
import sys | |
####### | |
####### IP Address | |
####### | |
IP_ADDR = '192.168.20.119' | |
####### | |
####### Mode should be `sacn` or `artnet` only | |
####### | |
THE_MODE = 'artnet' | |
####### | |
####### You want this 3 for RGB or 4 for RGBW pixels | |
####### | |
NUM_CHANNELS_PER_LED = 4 | |
####### | |
####### This is how many universes you want to send to, starting from 1 | |
####### | |
NUM_UNI = 3 | |
####### | |
####### The number of pixels per connector | |
####### | |
PIXELS_PER_CONNECTOR = 384 | |
####### | |
####### Uncomment the line below to see packets' bytes as they hit the wire | |
####### | |
#logging.basicConfig(level=logging.DEBUG) | |
async def main(): | |
if len(sys.argv) >= 2: | |
i = int(sys.argv[1]) | |
else: | |
i = 0 | |
if i < 0 or i > NUM_CHANNELS_PER_LED: | |
raise ValueError(f"Arg should in 0-{NUM_CHANNELS_PER_LED}, the color index") | |
#x = int(sys.argv[2]) | |
# This sets the max brightness we'll send out | |
x = 255 | |
# Run this code in your async function | |
if THE_MODE == 'sacn': | |
node = SacnNode(IP_ADDR, 5568, max_fps=30) | |
elif THE_MODE == 'artnet': | |
node = ArtNetNode(IP_ADDR, 6454, max_fps=30) | |
else: | |
raise ValueError(f"Mode should only be sacn or artnet") | |
node.set_output_correction(None) | |
channels = [] | |
NUM_UNI = 3 | |
NUM_CHANS = int(PIXELS_PER_CONNECTOR * 3/NUM_CHANNELS_PER_LED / NUM_UNI) | |
for u in range(NUM_UNI): | |
universe = node.add_universe(u+1) | |
for l in range(NUM_CHANS): | |
if l * 4 + 1 + 4 > 512: | |
raise ValueError(f"Would've overflowed the universe") | |
channel = universe.add_channel(start = l * 4+1, width=4) | |
channels.append((universe, channel)) | |
t = 0.9999999 | |
dt = -0.01 | |
while True: | |
val = [0] * NUM_CHANNELS_PER_LED | |
val[i] = int(x * t) | |
for (u,c) in channels: | |
#c.add_fade(val, 100) | |
c.set_values(val) | |
t += dt | |
if t > 1 or t < 0: | |
dt = -dt | |
t += dt | |
# GRBW | |
print(f"value is {int(x*t)}") | |
await asyncio.sleep(0.02) | |
await asyncio.sleep(0.2) | |
asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment