Esempio n. 1
0
def bitmapBlit(x, y, translatedBitmap):
    """
        Instead of filling the whole 128x64 framebuffer it renders only the region of a `translatedBitmap` on the screen at `x`, `y` location, sort of Direct Memory Access (DMA). Requires the `translatedBitmap` from `translateBitmap()` as input. Does not clear the `framebuffer` after.
    """
    # start = int(round(time.time() * 1000))
    bitmapHeight = len(translatedBitmap)
    bitmapWidth = len(translatedBitmap[0])
    bitmapPage = 0
    bufferPage = (y / OLED_PAGE_SIZE) % OLED_PAGES
    # print("Bitmap height: " + str(bitmapHeight))
    while bitmapPage < bitmapHeight:
        # print("Bitmap page: " + str(bitmapPage))
        oledExp.setCursorByPixel(bufferPage + bitmapPage, x)
        count = 0
        while count < bitmapWidth:
            lineWidth = bitmapWidth if bitmapWidth < OLED_I2C_MAX_BUFFER else (
                OLED_I2C_MAX_BUFFER if bitmapWidth -
                count > OLED_I2C_MAX_BUFFER else bitmapWidth - count)
            bytes = [
                translatedBitmap[bitmapPage][count + i]
                for i in range(lineWidth)
            ]
            i2c.writeBytes(OLED_EXP_ADDR, OLED_EXP_REG_DATA, bytes)
            count += lineWidth
        oledExp.setCursorByPixel(0, 0)
        bitmapPage += 1
Esempio n. 2
0
def pageBlit(pageNo, x, length):
    """ 
        Renders portion of a page, (row) with `length` starting from `x`, to screen at maximum fast rate. Does not clear the `framebuffer` after.
    """
    start = int(round(time.time() * 1000))
    oledExp.setCursorByPixel(pageNo, x)
    global pagebuffer
    count = 0
    while count < length:
        lineWidth = length if length < OLED_I2C_MAX_BUFFER else (
            OLED_I2C_MAX_BUFFER if length -
            count > OLED_I2C_MAX_BUFFER else length - count)
        bytes = [pagebuffer[pageNo][x + count + i] for i in range(lineWidth)]
        i2c.writeBytes(OLED_EXP_ADDR, OLED_EXP_REG_DATA, bytes)
        count += lineWidth
    oledExp.setCursorByPixel(0, 0)
    end = int(round(time.time() * 1000))
    print("pageBlit() took: " + str(end - start))
Esempio n. 3
0
# set the highest brightness
ret 	= oledExp.setBrightness(255)
print "setBrightness return: ", ret
if (ret != 0):
	exit()
time.sleep(2)


# clear the display
ret 	= oledExp.clear()
print "clear return: ", ret
if (ret != 0):
	exit()

# set the cursor by pixel
ret 	= oledExp.setCursorByPixel(1,64)
print "setCursorByPixel return: ", ret
if (ret != 0):
	exit()

# draw a few bytes 
ret 	= oledExp.writeByte(0x0f)
print "writeByte return: ", ret
ret 	= oledExp.writeByte(0xf0)
print "writeByte return: ", ret
ret 	= oledExp.writeByte(0x0f)
print "writeByte return: ", ret
ret 	= oledExp.writeByte(0xf0)
print "writeByte return: ", ret
time.sleep(2)
Esempio n. 4
0
# set the highest brightness
ret = oledExp.setBrightness(255)
print "setBrightness return: ", ret
if (ret != 0):
    exit()
time.sleep(2)

# clear the display
ret = oledExp.clear()
print "clear return: ", ret
if (ret != 0):
    exit()

# set the cursor by pixel
ret = oledExp.setCursorByPixel(1, 64)
print "setCursorByPixel return: ", ret
if (ret != 0):
    exit()

# draw a few bytes
ret = oledExp.writeByte(0x0f)
print "writeByte return: ", ret
ret = oledExp.writeByte(0xf0)
print "writeByte return: ", ret
ret = oledExp.writeByte(0x0f)
print "writeByte return: ", ret
ret = oledExp.writeByte(0xf0)
print "writeByte return: ", ret
time.sleep(2)
#get an idea of the algorithm at work
sleepTime = 1.0

#The algorithm works as follows.  Start with 3 vertices of a triangle and begin at
#one of them.  Randomly choose a vertex.  Go half way to that vertex and draw a point.
#Repeat until you are happy.

while True:
    #pick a vertex
    i = random.randint(0, 2)
    vert = vertices[i]

    #find the point halfway between
    currX = int((vert['x'] + currX) / 2)
    currY = int((vert['y'] + currY) / 2)

    #convert to columns and bit patterns
    col = int(currX / 8)
    bitX = 1 << (currX % 8)

    #OR the info into the existing data
    state[currY][col] |= int(state[currY][col] | bitX)

    #write the data to the display
    oled.setCursorByPixel(col, currY)
    oled.writeByte(state[currY][col])

    #and do some sleeping for dramatic effect
    time.sleep(sleepTime)
    sleepTime = sleepTime - (sleepTime / 20)