def main_artsync(universe, start_channel, end_channel, ip='127.0.0.1', tmp=5):
    target_ip = ip
    packet_size = 512
    port = 6454
    a = StupidArtnet(target_ip, port, universe, packet_size)
    packet = Animation.anime_2(packet_size, start_channel, end_channel)
    a.set(packet[0])
    file.write(StupidArtnet.print_object_and_packet(a))
    group = ArtNetGroup(a)
    group.start(True)
    time.sleep(tmp)
    group.stop()
    group.set(bytearray(512))
    group.show(True)
示例#2
0
a = StupidArtnet(target_ip, universe, packet_size)

# MORE ADVANCED CAN BE SET WITH SETTERS IF NEEDED
# NET         = DEFAULT 0
# SUBNET      = DEFAULT 0

# CHECK INIT
print(a)

# YOU CAN CREATE YOUR OWN BYTE ARRAY OF PACKET_SIZE
packet = bytearray(packet_size)  # create packet for Artnet
for i in range(packet_size):  # fill packet with sequential values
    packet[i] = (i % 256)

# ... AND SET IT TO STUPID ARTNET
a.set(packet)  # only on changes

# ALL PACKETS ARE SAVED IN THE CLASS, YOU CAN CHANGE SINGLE VALUES
a.set_single_value(1, 255)  # set channel 1 to 255

# ... AND SEND
a.show()  # send data

# OR USE STUPIDARTNET FUNCTIONS
a.flash_all()  # send single packet with all channels at 255

time.sleep(1)  # wait a bit, 1 sec

a.blackout()  # send single packet with all channels at 0
a.see_buffer()
示例#3
0
def main():
    a = StupidArtnet(ip, universe, packet_size)

    packet = bytearray(packet_size)  # create packet for Artnet
    vu = bytearray(int(packet_size / CHANNELS))  # create initial part of a VU
    # red
    for i in range(45, 50):  # TODO: CHANNELS
        vu[3 * i + 0] = 255
    # yellow
    for i in range(30, 45):  # TODO: CHANNELS
        vu[3 * i + 0] = 255
        vu[3 * i + 1] = 128
    # green
    for i in range(0, 30):  # TODO: CHANNELS
        vu[3 * i + 1] = 255

    stream = False
    audio = pyaudio.PyAudio()
    #device_index = find_input_device(audio)
    try:
        stream = audio.open(
            format=pyaudio.paInt16,
            channels=CHANNELS,
            rate=RATE,
            input=True,
            output=True,
            #input_device_index = 0,#device_index,
            frames_per_buffer=INPUT_FRAMES_PER_BLOCK)

        while True:
            block = stream.read(INPUT_FRAMES_PER_BLOCK)
            left, right = get_rms(block, CHANNELS)
            left /= THRESHOLD
            right /= THRESHOLD
            if (left > 1):
                left = 1
            if (right > 1):
                right = 1

            asciil = (" " * int(10 - left * 10)) + ("#" * int(left * 10))
            asciir = ("#" * int(right * 10) + (" " * int(10 - right * 10)))
            print("[{0}][{1}]\r".format(asciil, asciir), end="")

            left = int(left * ledAmount / CHANNELS)
            right = int(right * ledAmount / CHANNELS)

            for i in range(0, int(ledAmount / CHANNELS)):
                packet[147 - 3 * i] = vu[3 * i + 0] if i <= left else 0
                packet[148 - 3 * i] = vu[3 * i + 1] if i <= left else 0
                packet[149 - 3 * i] = vu[3 * i + 2] if i <= left else 0

            for i in range(0, int(ledAmount / CHANNELS)):
                packet[3 * i + 150] = vu[3 * i + 0] if i <= right else 0
                packet[3 * i + 151] = vu[3 * i + 1] if i <= right else 0
                packet[3 * i + 152] = vu[3 * i + 2] if i <= right else 0

            a.set(packet)
            a.show()
    finally:
        if (stream):
            stream.stop_stream()
            stream.close()
        audio.terminate()
示例#4
0
ip = "192.168.1.234"  # Change to correct IP address!
universe = 1
ledAmount = 50
packet_size = ledAmount * 3

#ACKtree = ChristmasTree.ChristmasTree(ip, port, ledAmount)
a = StupidArtnet(ip, universe, packet_size)

packet = bytearray(packet_size)  # create packet for Artnet

while 1:
    # Red on, blue off
    for i in range(0, ledAmount / 2):
        packet[3 * i + 0] = 255

    for i in range(ledAmount / 2, ledAmount):
        packet[3 * i + 2] = 0
    a.set(packet)
    a.show()
    time.sleep(0.3)

    # Blue on, red off
    for i in range(0, ledAmount / 2):
        packet[3 * i + 0] = 0

    for i in range(ledAmount / 2, ledAmount):
        packet[3 * i + 2] = 255
    a.set(packet)
    a.show()
    time.sleep(0.3)