UDP Panel ✓

Okay, one CCC project done. The panel now accepts data via UDP , if you send enough it will reset the whole panel, to something. It doesn't do what I want, but what it does right now is much much cooler than what I planned to do.

If I get time during congress I will do something more I guess. Here is all of the code so you can make your own and play a long at home.

import machine, neopixel, time, socket

LEDCOUNT = 64
skull = [
0,0,1,1,1,1,1,0,
0,1,1,1,1,1,1,1,
1,0,0,1,0,0,1,1,
1,0,0,1,0,0,1,1,
0,1,1,0,1,1,1,0,
0,0,0,1,1,1,0,0,
0,0,0,1,0,1,0,0,
0,0,0,0,0,0,0,0,]

def chunks(l, n):
    n = max(1, n)
    return [l[i:i + n] for i in range(0, len(l), n)]

if __name__ == "__main__":
    addr = "0.0.0.0"
    port = 6969

    pin = machine.Pin(14, machine.Pin.OUT)
    np = neopixel.NeoPixel(pin, LEDCOUNT)

    print("receiving from {} {}".format(addr, port))

    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True)

    sock.settimeout(1.0)
    sock.bind((addr,port))

    while True:
        try: 
            pkt,addr = sock.recvfrom(1024) #blocks
            print("addr {}".format(addr))
        except OSError: 
            pkt = b""

        colours = chunks(pkt, 3)
        if len(pkt) == 3*LEDCOUNT:
            for x in range(LEDCOUNT):
                np[x] = colour
        else:
            colour = (0,0,0)
            if not len(colours) % 3:
                colour = uos.urandom(3)
            else:
                colour = colours[0]

            for x in range(len(skull)):
                if skull[x]:
                    np[x] = colour
        np.write()
        time.sleep(0.16)

SlowTV is going slowly(lol), the project is all set up. I need to figure out how to get the pi to output at the teeny resolution it supports.


Reading: Nemesis Games, All Tomorrows Parties