Micropython学习交流群 学习QQ群:786510434 提供多种固件下载和学习交流。
Micropython-扇贝物联 QQ群:31324057 扇贝物联是一个让你与智能设备沟通更方便的物联网云平台
Micropython学习交流群 学习QQ群:468985481 学习交流ESP8266、ESP32、ESP8285、wifi模块开发交流、物联网。
Micropython老哥俩的IT农场分享QQ群:929132891 为喜欢科创制作的小白们分享一些自制的计算机软硬件免费公益课程,由两位多年从事IT研发的中年大叔发起。
ESP32(MicroPython)MAX7219点阵屏字符显示
本程序使用chr()函数把数字转换为ASCII字符进行显示,实测ASCII码在33到126的字符能正常显示。
代码如下
import max7219 from machine import Pin, SPI import time spi = SPI(1, baudrate=10000000, polarity=1, phase=0, sck=Pin(2), mosi=Pin(0)) ss = Pin(4, Pin.OUT) i=33 while True: display = max7219.Matrix8x8(spi, ss, 1) display.text(chr(i),0,0,1) display.show() print(i,chr(i)) time.sleep(0.2) i+=1 if i==127: i=33 外设驱动 """ MicroPython max7219 cascadable 8x8 LED matrix driver https://github.com/mcauser/micropython-max7219 MIT License Copyright (c) 2017 Mike Causer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ from micropython import const import framebuf _NOOP = const(0) _DIGIT0 = const(1) _DECODEMODE = const(9) _INTENSITY = const(10) _SCANLIMIT = const(11) _SHUTDOWN = const(12) _DISPLAYTEST = const(15) class Matrix8x8: def __init__(self, spi, cs, num): """ Driver for cascading MAX7219 8x8 LED matrices. >>> import max7219 >>> from machine import Pin, SPI >>> spi = SPI(1) >>> display = max7219.Matrix8x8(spi, Pin('X5'), 4) >>> display.text('1234',0,0,1) >>> display.show() """ self.spi = spi self.cs = cs self.cs.init(cs.OUT, True) self.buffer = bytearray(8 * num) self.num = num fb = framebuf.FrameBuffer(self.buffer, 8 * num, 8, framebuf.MONO_HLSB) self.framebuf = fb # Provide methods for accessing FrameBuffer graphics primitives. This is a workround # because inheritance from a native class is currently unsupported. # http://docs.micropython.org/en/latest/pyboard/library/framebuf.html self.fill = fb.fill # (col) self.pixel = fb.pixel # (x, y[, c]) self.hline = fb.hline # (x, y, w, col) self.vline = fb.vline # (x, y, h, col) self.line = fb.line # (x1, y1, x2, y2, col) self.rect = fb.rect # (x, y, w, h, col) self.fill_rect = fb.fill_rect # (x, y, w, h, col) self.text = fb.text # (string, x, y, col=1) self.scroll = fb.scroll # (dx, dy) self.blit = fb.blit # (fbuf, x, y[, key]) self.init() def _write(self, command, data): self.cs(0) for m in range(self.num): self.spi.write(bytearray([command, data])) self.cs(1) def init(self): for command, data in ( (_SHUTDOWN, 0), (_DISPLAYTEST, 0), (_SCANLIMIT, 7), (_DECODEMODE, 0), (_SHUTDOWN, 1), ): self._write(command, data) def brightness(self, value): if not 0 <= value <= 15: raise ValueError("Brightness out of range") self._write(_INTENSITY, value) def show(self): for y in range(8): self.cs(0) for m in range(self.num): self.spi.write(bytearray([_DIGIT0 + y, self.buffer[(y * self.num) + m]])) self.cs(1)
————————————————
版权声明:本文为CSDN博主「路易斯720」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_74155302/article/details/131351253
Copyright © 2014 ESP56.com All Rights Reserved
执行时间: 0.0079309940338135 seconds