Example #1
0
def display():
    with open('rect.png', 'rb') as f:
        img = png.Reader(file=f)
        #print(img.read())
        width, height, pixels, options = img.read()
        if width != 32 or height != 8:
            raise Exception("bad size")

        with serial.Serial("COM5") as com:
            com.timeout = 3
            wait_ready(com)

            for row, line_pixels in enumerate(pixels):
                print(line_pixels)
                tmp = 0
                for col, pixel in enumerate(line_pixels):
                    tmp = tmp << 1
                    tmp = tmp | pixel

                    if col % 8 == 7:
                        print(tmp)
                        com.write(struct.pack('BB', 0x01 + row, tmp))
                        tmp = 0
                        # wait_ready(com)
                        # os.system("pause")

                wait_ready(com)
Example #2
0
def blank(com):
    #output_all(0x0a, 0x0f); //

    for r in range(8):
        for n in range(MAX7219_COUNT):
            if r == 0 and n == 0:
                com.write(struct.pack('BB', 0x01 + r, 1))
            else:
                com.write(struct.pack('BB', 0x01 + r, 0))

        wait_ready(com)
Example #3
0
    def arduino_0x04(self, com):
        data = []
        for r in range(8):
            data = data + self.stream[r].tolist()
        # print(data)
        data = rle_encode(data)
        logger.debug("data.len: %s" % len(data))

        com.write(struct.pack('B', 0x04))
        for item in data:
            com.write(struct.pack('B', item))

        wait_ready(com)
Example #4
0
def draw(com):
    for source_y in range(24):
        for source_x in range(32):
            if source_y >= 16:
                x = 0
            elif source_y >= 8:
                x = 4
            else:
                x = 8

            x = x + source_x / 8
            y = source_y % 8
            v = 1 << 7 - source_x % 8

            stream = np.full((8, MAX7219_COUNT), 0)
            stream[y][x] = v

            for r in range(8):
                for v in stream[r]:
                    com.write(struct.pack('BB', 0x01 + r, v))
                wait_ready(com)
Example #5
0
    scoreLeft = now.hour
    scoreRight = now.minute

    start_pos = (12, 12)
    impulse = np.array((1, 3))
    impulse = np.array((random.random(), random.random()))
    impulse = impulse / np.linalg.norm(impulse)
    # impulse = impulse/10

    paddle_left_pos = 12
    paddle_right_pos = 12

    with serial.Serial("COM5") as com:
        com.timeout = 3
        wait_ready(com)

        com.write(struct.pack('BBB', 0x01, 0x0a, 0x01))  #brightness
        wait_ready(com)

        t = 0
        last_pos = None
        while True:
            pos_t = impulse * t
            pos_t = map(lambda x: int(round(x)), pos_t)

            pos_t[0] = pos_t[0] + start_pos[0]
            pos_t[1] = pos_t[1] + start_pos[1]

            if (pos_t[1] < 0 or pos_t[1] >= 24):
                impulse[1] = impulse[1] * -1
Example #6
0
 def arduino_0x03(self, com):
     com.write(struct.pack('B', 0x03))
     for r in range(8):
         for v in self.stream[r]:
             com.write(struct.pack('B', v))
     wait_ready(com)