# import max7219
# from machine import Pin, SPI
# from time import sleep
# # Initialize SPI
# spi = SPI(0, baudrate=10000000, polarity=0, phase=0, sck=Pin(2), mosi=Pin(3))
# # Initialize the MAX7219 display with 1 matrix, using CS on GPIO 5
# display = max7219.Matrix8x8(spi, Pin(5), 4)
# display.brightness(10)
# scrolling_message = "SCROLLING"
# length = len(scrolling_message)
# column = (length * 8)
# display.fill(0)
# display.show()
# sleep(1)
# while True:
# for x in range(32, -column, -1):
# display.fill(0)
# display.text(scrolling_message ,x,0,1)
# display.show()
# sleep(0.1)
import max7219
from machine import Pin, SPI
# Initialize SPI
spi = SPI(0, baudrate=10000000, polarity=0, phase=0, sck=Pin(2), mosi=Pin(3))
# Initialize the MAX7219 display with 1 matrix
display = max7219.Matrix8x8(spi, Pin(5), 16)
# Clear the display
display.fill(0)
# Draw a horizontal line
# for x in range(8):
display.pixel(10, 7, 1) # Line at y=3
# # Draw a vertical line
# for y in range(8):
# display.pixel(4, y, 1) # Line at x=4
display.show()
# import max7219
# from machine import Pin, SPI
# # Initialize SPI interface
# spi = SPI(0, baudrate=10000000, polarity=0, phase=0, sck=Pin(2), mosi=Pin(3))
# # Initialize the MAX7219 with 4 cascaded displays (considered linear in code)
# display = max7219.Matrix8x8(spi, Pin(5), 4)
# # Clear the display before starting
# display.fill(0)
# # Top row (matrix 1 and 2, for numbers 1234)
# display.text('12', 0, 0, 1) # Top-left (matrix 1)
# display.text('34', 16, 0, 1) # Top-right (matrix 2)
# # Bottom row (matrix 3 and 4, for numbers 5678)
# display.text('56', 0, 8, 1) # Bottom-left (matrix 3)
# display.text('78', 16, 8, 1) # Bottom-right (matrix 4)
# # Update the display with the new content
# display.show()
# # import max7219
# # from machine import Pin, SPI
# # # Initialize SPI with appropriate baudrate and pins
# # spi = SPI(0, baudrate=10000000, polarity=0, phase=0, sck=Pin(2), mosi=Pin(3))
# # # Initialize the MAX7219 display with 16 matrices (4 chains of 4 displays)
# # # Change 'Pin(5)' if you are using a different pin for CS
# # display = max7219.Matrix8x8(spi, Pin(5), 4)
# # # Clear the display initially
# # display.fill(0)
# # # Display text or shapes across the 16 matrices
# # # For example, scrolling text across the full display
# # display.text('HELLO WORLD', 0, 0, 1)
# # display.show()
# # # To scroll the text, you could move it left every frame:
# # import time
# # for i in range(64): # Loop through each column to shift the text
# # display.fill(0)
# # display.text('HELLO WORLD', -i, 0, 1) # Move text to the left
# # display.show()
# # time.sleep(0.1)
# import max7219
# from machine import Pin, SPI
# # Initialize SPI interface
# spi = SPI(0, baudrate=10000000, polarity=0, phase=0, sck=Pin(2), mosi=Pin(3))
# # Initialize the MAX7219 with 4 cascaded displays (in linear mode, but we'll remap them)
# display = max7219.Matrix8x8(spi, Pin(5), 4)
# # Clear the display before starting
# display.fill(0)
# # Function to write flipped text on inverted displays (mirroring characters)
# def flipped_text(display, text, x, y):
# # Write text mirrored by reversing it
# for i in range(len(text)):
# display.text(text[i], x + 8 * (len(text) - 1 - i), y, 1)
# # Write to individual displays considering snake layout
# # Top row (Display 1 - top-left, Display 2 - top-right)
# display.text('12', 0, 0, 1) # Top-left (normal orientation)
# flipped_text(display, '34', 16, 0) # Top-right (inverted, needs flipping)
# # Bottom row (Display 3 - bottom-left, Display 4 - bottom-right)
# display.text('56', 0, 8, 1) # Bottom-left (normal orientation)
# flipped_text(display, '78', 16, 8) # Bottom-right (inverted, needs flipping)
# # Update the display
# display.show()