PCtoLCD图像取模oled绘制,主要还是自己懂
oled显示图像,网上有很多方案
无外乎取模--》绘制
这里重新整理一次
需求:要绘制一个48x48的方图在x,y
首先在PCtoLCD中取模
这里使用最形象的绘制过程:
从上到下 一行一行的绘制点,
所以需要一个二维数组代表这个图片
图像宽48个像素,取模的时候每8个像素用一个数字代表,那么每行就是6个数字,所以这里点阵为6,即每一行有6个数字
图像高48个像素,所以生成的数字应该有48个一维x数组
生成的模
[0x00,0x00,0x00,0x00,0x00,0x00], [0x00,0x00,0x00,0x00,0x00,0x00], [0x00,0x00,0x00,0x00,0x00,0x00], [0x00,0x00,0x00,0x00,0x00,0x00], [0x00,0x00,0x00,0x00,0x00,0x00], [0x00,0x00,0x00,0x00,0x00,0x00], [0x00,0x00,0x00,0x00,0x00,0x01], [0x00,0x00,0x00,0x00,0x00,0x01], [0x00,0x00,0x00,0x00,0x00,0x03], [0x00,0x00,0x00,0x00,0x00,0x06], [0x00,0x00,0x00,0x00,0x00,0x04], [0x00,0x00,0x00,0x00,0x00,0x0C], [0x00,0x00,0x00,0x00,0x00,0x18], [0x00,0x00,0x00,0x00,0x00,0x30], [0x00,0x00,0x00,0x00,0x00,0x60], [0x00,0x00,0x00,0x00,0x00,0xC0], [0x00,0x00,0x00,0x00,0x00,0x80], [0x00,0x00,0x00,0x00,0x01,0x80], [0x00,0x00,0x00,0x00,0x03,0x00], [0x00,0x00,0x00,0x00,0x06,0x00], [0x00,0x00,0x00,0x00,0x0C,0x00], [0x00,0x00,0x00,0x00,0x18,0x00], [0x00,0x00,0x00,0x00,0x30,0x00], [0x00,0x00,0x00,0x00,0x60,0x00], [0x00,0x00,0x00,0x00,0xC0,0x00], [0x00,0x00,0x00,0x01,0x80,0x00], [0x10,0x00,0x00,0x03,0x00,0x00], [0x10,0x00,0x00,0x06,0x00,0x00], [0x18,0x00,0x00,0x0C,0x00,0x00], [0x08,0x00,0x00,0x18,0x00,0x00], [0x0C,0x00,0x00,0x30,0x00,0x00], [0x04,0x00,0x00,0xC0,0x00,0x00], [0x06,0x00,0x01,0x80,0x00,0x00], [0x02,0x00,0x03,0x00,0x00,0x00], [0x03,0x00,0x0C,0x00,0x00,0x00], [0x01,0x80,0x38,0x00,0x00,0x00], [0x00,0xC0,0xE0,0x00,0x00,0x00], [0x00,0x61,0x80,0x00,0x00,0x00], [0x00,0x3E,0x00,0x00,0x00,0x00], [0x00,0x00,0x00,0x00,0x00,0x00], [0x00,0x00,0x00,0x00,0x00,0x00], [0x00,0x00,0x00,0x00,0x00,0x00], [0x00,0x00,0x00,0x00,0x00,0x00], [0x00,0x00,0x00,0x00,0x00,0x00], [0x00,0x00,0x00,0x00,0x00,0x00], [0x00,0x00,0x00,0x00,0x00,0x00], [0x00,0x00,0x00,0x00,0x00,0x00], [0x00,0x00,0x00,0x00,0x00,0x00],
使用方法
from machine import Pin, I2C from ssd1306 import SSD1306_I2C import time print("ssd") display = None def check(): print('connect oled module to esp8266') global display while True: print('connecting') i2c = I2C(scl=Pin(5), sda=Pin(4)) addr = i2c.scan() if len(addr): display = SSD1306_I2C(128, 64, i2c, addr=addr[0]) print('connected') break time.sleep(1) check() x_axis=0 y_axis=0 byte_data = [ [0x00,0x00,0x00,0x00,0x00,0x00], [0x00,0x00,0x00,0x00,0x00,0x00], [0x00,0x00,0x00,0x00,0x00,0x00], [0x00,0x00,0x00,0x00,0x00,0x00], [0x00,0x00,0x00,0x00,0x00,0x00], [0x00,0x00,0x00,0x00,0x00,0x00], [0x00,0x00,0x00,0x00,0x00,0x01], [0x00,0x00,0x00,0x00,0x00,0x01], [0x00,0x00,0x00,0x00,0x00,0x03], [0x00,0x00,0x00,0x00,0x00,0x06], [0x00,0x00,0x00,0x00,0x00,0x04], [0x00,0x00,0x00,0x00,0x00,0x0C], [0x00,0x00,0x00,0x00,0x00,0x18], [0x00,0x00,0x00,0x00,0x00,0x30], [0x00,0x00,0x00,0x00,0x00,0x60], [0x00,0x00,0x00,0x00,0x00,0xC0], [0x00,0x00,0x00,0x00,0x00,0x80], [0x00,0x00,0x00,0x00,0x01,0x80], [0x00,0x00,0x00,0x00,0x03,0x00], [0x00,0x00,0x00,0x00,0x06,0x00], [0x00,0x00,0x00,0x00,0x0C,0x00], [0x00,0x00,0x00,0x00,0x18,0x00], [0x00,0x00,0x00,0x00,0x30,0x00], [0x00,0x00,0x00,0x00,0x60,0x00], [0x00,0x00,0x00,0x00,0xC0,0x00], [0x00,0x00,0x00,0x01,0x80,0x00], [0x10,0x00,0x00,0x03,0x00,0x00], [0x10,0x00,0x00,0x06,0x00,0x00], [0x18,0x00,0x00,0x0C,0x00,0x00], [0x08,0x00,0x00,0x18,0x00,0x00], [0x0C,0x00,0x00,0x30,0x00,0x00], [0x04,0x00,0x00,0xC0,0x00,0x00], [0x06,0x00,0x01,0x80,0x00,0x00], [0x02,0x00,0x03,0x00,0x00,0x00], [0x03,0x00,0x0C,0x00,0x00,0x00], [0x01,0x80,0x38,0x00,0x00,0x00], [0x00,0xC0,0xE0,0x00,0x00,0x00], [0x00,0x61,0x80,0x00,0x00,0x00], [0x00,0x3E,0x00,0x00,0x00,0x00], [0x00,0x00,0x00,0x00,0x00,0x00], [0x00,0x00,0x00,0x00,0x00,0x00], [0x00,0x00,0x00,0x00,0x00,0x00], [0x00,0x00,0x00,0x00,0x00,0x00], [0x00,0x00,0x00,0x00,0x00,0x00], [0x00,0x00,0x00,0x00,0x00,0x00], [0x00,0x00,0x00,0x00,0x00,0x00], [0x00,0x00,0x00,0x00,0x00,0x00], [0x00,0x00,0x00,0x00,0x00,0x00] ] print('byte_data',len(byte_data)) #print(fonts[k], "offset=", offset_) for y in range(len(byte_data)): line='' for x8 in range(len(byte_data[y])): # 进制转换、补全 a_ = '{:0>8b}'.format(byte_data[y][x8]) line=line+a_ for x in range(0, 8): display.pixel( x+(x8*8), y , int(a_[x])) print('y',y,'line',line)
可以很形象的看出绘制的来源
之后可以优化为函数,也可以直接操作一维数组