/ adafruit_max7219 / matrices.py
matrices.py
1 # The MIT License (MIT) 2 # 3 # Copyright (c) 2017 Dan Halbert 4 # 5 # Permission is hereby granted, free of charge, to any person obtaining a copy 6 # of this software and associated documentation files (the "Software"), to deal 7 # in the Software without restriction, including without limitation the rights 8 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 # copies of the Software, and to permit persons to whom the Software is 10 # furnished to do so, subject to the following conditions: 11 # 12 # The above copyright notice and this permission notice shall be included in 13 # all copies or substantial portions of the Software. 14 # 15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 # THE SOFTWARE. 22 # 23 24 """ 25 `adafruit_max7219.matrices.Matrix8x8` 26 ==================================================== 27 """ 28 from micropython import const 29 from adafruit_max7219 import max7219 30 31 __version__ = "0.0.0-auto.0" 32 __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_MAX7219.git" 33 34 _DECODEMODE = const(9) 35 _SCANLIMIT = const(11) 36 _SHUTDOWN = const(12) 37 _DISPLAYTEST = const(15) 38 39 40 class Matrix8x8(max7219.MAX7219): 41 """ 42 Driver for a 8x8 LED matrix based on the MAX7219 chip. 43 44 :param object spi: an spi busio or spi bitbangio object 45 :param ~digitalio.DigitalInOut cs: digital in/out to use as chip select signal 46 """ 47 48 def __init__(self, spi, cs): 49 super().__init__(8, 8, spi, cs) 50 51 def init_display(self): 52 for cmd, data in ( 53 (_SHUTDOWN, 0), 54 (_DISPLAYTEST, 0), 55 (_SCANLIMIT, 7), 56 (_DECODEMODE, 0), 57 (_SHUTDOWN, 1), 58 ): 59 self.write_cmd(cmd, data) 60 61 self.fill(0) 62 self.show() 63 64 def text(self, strg, xpos, ypos, bit_value=1): 65 """ 66 Draw text in the 8x8 matrix. 67 68 :param int xpos: x position of LED in matrix 69 :param int ypos: y position of LED in matrix 70 :param string strg: string to place in to display 71 :param bit_value: > 1 sets the text, otherwise resets 72 """ 73 self.framebuf.text(strg, xpos, ypos, bit_value) 74 75 def clear_all(self): 76 """ 77 Clears all matrix leds. 78 """ 79 self.fill(0)