0% found this document useful (0 votes)
4 views2 pages

Code

This document contains a Python script that interfaces with a MAX7219 LED display using the SPI protocol. It initializes the display, defines a simple font for characters, and includes functions to display characters and scroll messages. The main function initializes the display and scrolls the message 'HI HI HI' across the LED matrix.

Uploaded by

mango
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Code

This document contains a Python script that interfaces with a MAX7219 LED display using the SPI protocol. It initializes the display, defines a simple font for characters, and includes functions to display characters and scroll messages. The main function initializes the display and scrolls the message 'HI HI HI' across the LED matrix.

Uploaded by

mango
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

import spidev

import time

# Open SPI
spi = [Link]()
[Link](0, 0) # bus 0, device 0 (CE0)
spi.max_speed_hz = 8000000

def send_cmd(register, data):


[Link]([register, data])

def init_max7219():
send_cmd(0x09, 0x00) # Decode mode off
send_cmd(0x0A, 0x03) # Brightness (0x00 - 0x0F)
send_cmd(0x0B, 0x07) # Scan limit = full matrix
send_cmd(0x0C, 0x01) # Shutdown register = normal operation
send_cmd(0x0F, 0x00) # Display test = off
clear()

def clear():
for i in range(1, 9):
send_cmd(i, 0x00)

# Simple font for characters


FONT = {
"H": [0x7E, 0x08, 0x08, 0x08, 0x7E],
"I": [0x00, 0x42, 0x7E, 0x42, 0x00],
" ": [0x00,0x00,0x00,0x00,0x00]
}

def display_char(char):
pattern = [Link](char, FONT[" "])
for row in range(8):
col_data = 0
for col in range(5):
if (pattern[col] >> row) & 1:
col_data |= (1 << (7 - col))
send_cmd(row + 1, col_data)

def scroll_message(text, delay=0.2):


for char in text:
display_char(char)
[Link](delay)
clear()
# MAIN
init_max7219()
scroll_message("HI HI HI ")

You might also like