コード例 #1
0
def show_bitmap(filename):
    set_pos()
    command([0xae])
    with open(filename, 'rb') as my_file:
        for i in range(0, 16):
            i2c.write(ADDR, b'\x40' + my_file.read(64))
    set_zoom(0)
    command([0xaf])
コード例 #2
0
def set_px(x, y, color, draw=1):
    page, shift_page = divmod(y, 8)
    ind = x * 2 + page * 128 + 1
    b = screen[ind] | (
        1 << shift_page) if color else screen[ind] & ~(1 << shift_page)
    pack_into(">BB", screen, ind, b, b)
    if draw:
        set_pos(x, page)
        i2c.write(0x3c, bytearray([0x40, b, b]))
コード例 #3
0
def add_text(x, y, text, draw=1):
    for i in range(0, min(len(text), 12 - x)):
        for c in range(0, 5):
            col = 0
            for r in range(1, 6):
                p = Image(text[i]).get_pixel(c, r - 1)
                col = col | (1 << r) if (p != 0) else col
            ind = x * 10 + y * 128 + i * 10 + c * 2 + 1
            screen[ind], screen[ind + 1] = col, col
    if draw == 1:
        set_zoom(1)
        set_pos(x * 5, y)
        ind0 = x * 10 + y * 128 + 1
        i2c.write(ADDR, b'\x40' + screen[ind0:ind + 1])
コード例 #4
0
def draw_stamp(x, y, stamp, color, draw=1):
    page, shift_page = divmod(y, 8)
    ind = (x << 1) + (page << 7) + 1
    if ind > 0:
        for col in range(0, 5):
            index = ind + (col << 1)
            b = (screen[index] | (stamp[col] << shift_page)) if color else (
                screen[index] & ~(stamp[col] << shift_page))
            pack_into(">BB", screen, index, b, b)
    ind += 128
    if ind < 513:
        for col in range(0, 5):
            index = ind + col * 2
            b = (screen[index] | (stamp[col] >> (8 - shift_page))
                 ) if color else screen[index] & ~(stamp[col] >>
                                                   (8 - shift_page))
            pack_into(">BB", screen, index, b, b)
    if draw:
        offset = 2 if x != 0 else 0
        set_pos(x - (offset >> 1), page)
        i2c.write(ADDR, b'\x40' + screen[ind - 128 - offset:ind - 116])
        if page < 3:
            set_pos(x - (offset >> 1), page + 1)
            i2c.write(ADDR, b'\x40' + screen[ind - offset:ind + 14])