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) ret = oledExp.setCursorByPixel(1, 127) print "setCursorByPixel return: ", ret if (ret != 0): exit() # draw a few bytes
# 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) ret = oledExp.setCursorByPixel(1,127) print "setCursorByPixel return: ", ret if (ret != 0): exit() # draw a few bytes
#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)