|
楼主 |
发表于 2020-4-19 20:04
|
显示全部楼层
3、通过A、B按键,控制OLED屏幕显示A或B
[mw_shl_code=arduino,true]#MicroPython动手做(13)——掌控板之RGB三色灯
#通过A、B按键,控制OLED屏幕显示A或B
from mpython import *
import framebuf
import font.dvsm_16
def display_font(_font, _str, _x, _y, _wrap, _z=0):
_start = _x
for _c in _str:
_d = _font.get_ch(_c)
if _wrap and _x > 128 - _d[2]: _x = _start; _y += _d[1]
if _c == '1' and _z > 0: oled.fill_rect(_x, _y, _d[2], _d[1], 0)
oled.blit(framebuf.FrameBuffer(bytearray(_d[0]), _d[2], _d[1],
framebuf.MONO_HLSB), (_x+int(_d[2]/_z)) if _c=='1' and _z>0 else _x, _y)
_x += _d[2]
while True:
if button_a.value() == 0:
oled.fill(0)
display_font(font.dvsm_16, "A", 62, 26, False)
oled.show()
if button_b.value() == 0:
oled.fill(0)
display_font(font.dvsm_16, "B", 62, 26, False)
oled.show()[/mw_shl_code]
|
|