Skip to content

Commit 18a1f19

Browse files
committed
ledmatrix_control: Add more patterns
Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent ae31745 commit 18a1f19

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

ledmatrix_control.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,19 @@ class GameControlVal(IntEnum):
106106
'"PANIC"',
107107
'"LOTUS" Top Down',
108108
'All brightness levels (1 LED each)',
109+
'Every Second Row',
110+
'Every Third Row',
111+
'Every Fourth Row',
112+
'Every Fifth Row',
113+
'Every Sixth Row',
114+
'Every Second Col',
115+
'Every Third Col',
116+
'Every Fourth Col',
117+
'Every Fifth Col',
118+
'Checkerboard',
119+
'Double Checkerboard',
120+
'Triple Checkerboard',
121+
'Quad Checkerboard'
109122
]
110123
DRAW_PATTERNS = ['off', 'on', 'foo']
111124
GREYSCALE_DEPTH = 32
@@ -578,6 +591,36 @@ def set_color(color):
578591
send_command(dev, CommandVals.SetColor, rgb)
579592

580593

594+
def checkerboard(dev, n):
595+
with serial.Serial(dev.device, 115200) as s:
596+
for x in range(0, WIDTH):
597+
vals = (([0xFF] * n) + ([0x00] * n)) * int(HEIGHT/2)
598+
if x % (n*2) < n:
599+
# Rotate once
600+
vals = vals[n:] + vals[:n]
601+
602+
send_col(s, x, vals)
603+
commit_cols(s)
604+
605+
606+
def every_nth_col(dev, n):
607+
with serial.Serial(dev.device, 115200) as s:
608+
for x in range(0, WIDTH):
609+
vals = [(0xFF if x % n == 0 else 0) for _ in range(HEIGHT)]
610+
611+
send_col(s, x, vals)
612+
commit_cols(s)
613+
614+
615+
def every_nth_row(dev, n):
616+
with serial.Serial(dev.device, 115200) as s:
617+
for x in range(0, WIDTH):
618+
vals = [(0xFF if y % n == 0 else 0) for y in range(HEIGHT)]
619+
620+
send_col(s, x, vals)
621+
commit_cols(s)
622+
623+
581624
def all_brightnesses(dev):
582625
"""Increase the brightness with each pixel.
583626
Only 0-255 available, so it can't fill all 306 LEDs"""
@@ -938,6 +981,32 @@ def pattern(dev, p):
938981
send_command(dev, CommandVals.Pattern, [PatternVals.DisplayLotus2])
939982
elif p == 'All brightness levels (1 LED each)':
940983
all_brightnesses(dev)
984+
elif p == 'Every Second Row':
985+
every_nth_row(dev, 2)
986+
elif p == 'Every Third Row':
987+
every_nth_row(dev, 3)
988+
elif p == 'Every Fourth Row':
989+
every_nth_row(dev, 4)
990+
elif p == 'Every Fifth Row':
991+
every_nth_row(dev, 5)
992+
elif p == 'Every Sixth Row':
993+
every_nth_row(dev, 6)
994+
elif p == 'Every Second Col':
995+
every_nth_col(dev, 2)
996+
elif p == 'Every Third Col':
997+
every_nth_col(dev, 3)
998+
elif p == 'Every Fourth Col':
999+
every_nth_col(dev, 4)
1000+
elif p == 'Every Fifth Col':
1001+
every_nth_col(dev, 4)
1002+
elif p == 'Checkerboard':
1003+
checkerboard(dev, 1)
1004+
elif p == 'Double Checkerboard':
1005+
checkerboard(dev, 2)
1006+
elif p == 'Triple Checkerboard':
1007+
checkerboard(dev, 3)
1008+
elif p == 'Quad Checkerboard':
1009+
checkerboard(dev, 4)
9411010
else:
9421011
print("Invalid pattern")
9431012

0 commit comments

Comments
 (0)