Maxim MAX7219 8x8 LED matrix driver.
The Maxim MAX7219 (and compatible MAX7221, and MAX6951) drives 8x8 matrices of LEDs commonly found in multi-digit 7-segment displays, as well as LED dot matrices. Because of the proliferation of low-cost MAX7219 dev boards on eBay, Amazon, and other popular retailers, these devices have been popular among hobbyists and students.
Examples
>>> from time import sleep
>>> board.connect()
>>> driver = Max7219(spi_module=board.spi, load_pin=board.pins[15])
>>> for led in driver.leds:
>>> led.state = True
>>> sleep(0.01)
>>> for led in driver.leds:
>>> led.state = False
>>> sleep(0.01)
The driver also supports chaining multiple MAX7219 ICs together with the parent property.
>>> driver1 = Max7219(spi_module=board.spi, load_pin=board.pins[15])
>>> driver2 = Max7219(parent=driver1)
>>> driver3 = Max7219(parent=driver2)
>>> leds = driver3.leds + driver2.leds + driver1.leds
>>> for led in leds:
>>> led.state = True
>>> sleep(0.01)
>>> for led in leds:
>>> led.state = False
>>> sleep(0.01)
By default, this driver orders the LEDs using the Treehopper convention for seven-segment LEDs (A-DP), which allows hooking up a SevenSegmentDisplay class directly to the LED collection to create a display you can print numbers (and some letters) to.
>>> display = SevenSegmentDisplay(leds)
>>> i = 0
>>> while board.connected:
>>> display.clear()
>>> display.write(i)
>>> i += 1
Whether to use the native LED order of the MAX7219, or the standard for Treehopper drivers.
If True, LED segments are ordered G-A, DP. If False, LED segments are ordered A-DP. All Treehopper LED driver libraries are, by default, standardized so that the LSB of the driver corresponds with segment "A", the 7th bit corresponds with "G" and the MSB corresponds to the "DP" segment. This allows easy consumption of display libraries that require ordered collections of segments. However, you may choose to work with this library using the native LED ordering, where the LSB corresponds with segment "G", the 7th bit corresponds to segment "A" and the MSB corresponds to segment "DP".