This commit is contained in:
Merrick Rumel 2025-01-29 11:06:29 -05:00 committed by GitHub
commit 1c4dfe5350
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 21228 additions and 0 deletions

Binary file not shown.

89
Code/led.py Normal file
View file

@ -0,0 +1,89 @@
import json
import zipfile
from ledMatrix import Animation
matrixWith = 39
matrixHeight = 15
def askQuestion():
global matrixWith, matrixHeight
while True:
col = int(input("Column [0-" + str(matrixWith) + "]: "))
if matrixWith >= col >= 0:
break
else:
print("Column Number Must be Between 0 and " + str(matrixWith))
while True:
row = int(input("Row [0-" + str(matrixHeight) + "]: "))
if matrixHeight >= row >= 0:
break
else:
print("Row Number Must be Between 0 and " + str(matrixHeight))
print("LED Number: " + str(getLedNumber(col, row)))
def getLedNumber(column, row):
global matrixWith, matrixHeight
pcbNum = int(column / 2)
colNum = column % 2
if colNum == 0:
return (matrixHeight - row) + (pcbNum * ((matrixHeight + 1) * 2))
else:
return ((matrixHeight + 1) + row) + (pcbNum * ((matrixHeight + 1) * 2))
def compressFileToString(inputFile):
"""
read the given open file, compress the data and return it as string.
"""
stream = StringIO()
compressor = gzip.GzipFile(fileobj=stream, mode='w')
while True: # until EOF
chunk = inputFile.read(8192)
if not chunk: # EOF?
compressor.close()
return stream.getvalue()
compressor.write(chunk)
def saveAnimationData(animation, fileName):
datFile = open(fileName, 'wb')
for l in range(0, len(animation.matrices)): # Write whole animation
for i in range(0, len(animation.matrices[0].panels)): # Write frame of animation
for j in range(0, len(animation.matrices[0].panels[0].leds)): # Write data for individual panel
datFile.write(
animation.matrices[l].panels[i].leds[j].r.to_bytes(1, byteorder='big')) # Write red value for led
datFile.write(
animation.matrices[l].panels[i].leds[j].g.to_bytes(1, byteorder='big')) # Write green value for led
datFile.write(
animation.matrices[l].panels[i].leds[j].b.to_bytes(1, byteorder='big')) # Write blue value for led
datFile.close()
def loadAnimationData(fileName):
datFile = open(fileName, 'rb')
retAnimation = Animation()
for i in range(0, len(retAnimation.matrices)): # Read whole animation
for j in range(0, len(retAnimation.matrices[0].panels)): # Read frame of animation
for k in range(0, len(retAnimation.matrices[0].panels[0].leds)): # Read data for individual panel
retAnimation.matrices[i].panels[j].leds[k].r = datFile.read(1) # Read red
retAnimation.matrices[i].panels[j].leds[k].g = datFile.read(1) # Read green
retAnimation.matrices[i].panels[j].leds[k].b = datFile.read(1) # Read blue
return retAnimation
if __name__ == "__main__":
# askQuestion()
# mainMatrix = Matrix()
mainAnimation = Animation()
saveAnimationData(mainAnimation, 'testAnimation.dat')
with zipfile.ZipFile('testAnimation.zip', 'w', zipfile.ZIP_DEFLATED) as myzip:
myzip.write('testAnimation.dat')
# arr = bytearray(mainAnimation)
# print(arr)
# file.write(arr)

49
Code/ledMatrix.py Normal file
View file

@ -0,0 +1,49 @@
import json
import random
class Animation:
def __init__(self):
self.matrices = []
for x in range(0, 50):
self.matrices.append(Matrix())
def play(self):
for x in range(len(self.matrices)):
self.matrices[x].setMatrixLights()
class Matrix:
def __init__(self):
self.panels = []
for x in range(0, 20):
self.panels.append(Panel(x))
def setMatrixLights(self):
for x in range(len(self.panels)):
self.panels[x].setPanelLights()
class Panel:
def __init__(self, panelNumber):
self.panelNumber = panelNumber
self.leds = []
for x in range(0, 16):
# Might have to look at this math later
self.leds.append(LED((16*panelNumber)+x))
def setPanelLights(self):
for x in range(len(self.leds)):
self.leds[x].setLedColor()
class LED:
def __init__(self, ledNumber):
self.ledNumber = ledNumber
self.r = random.randrange(0, 255)
self.g = random.randrange(0, 255)
self.b = random.randrange(0, 255)
def setLedColor(self): # Implement later with actual WS2813 lib function
# self.ledNumber.set(r,g,b)
return

103
Code/testfile.py Normal file
View file

@ -0,0 +1,103 @@
import array, time
from machine import Pin
import rp2
# Configure the number of WS2812 LEDs.
NUM_LEDS = 64
PIN_NUM = 13
brightness = 0.1
@rp2.asm_pio(sideset_init=rp2.PIO.OUT_LOW, out_shiftdir=rp2.PIO.SHIFT_LEFT, autopull=True, pull_thresh=24)
def ws2812():
T1 = 2
T2 = 5
T3 = 3
wrap_target()
label("bitloop")
out(x, 1) .side(0) [T3 - 1]
jmp(not_x, "do_zero") .side(1) [T1 - 1]
jmp("bitloop") .side(1) [T2 - 1]
label("do_zero")
nop() .side(0) [T2 - 1]
wrap()
# Create the StateMachine with the ws2812 program, outputting on pin
sm = rp2.StateMachine(0, ws2812, freq=8_000_000, sideset_base=Pin(PIN_NUM))
# Start the StateMachine, it will wait for data on its FIFO.
sm.active(1)
# Display a pattern on the LEDs via an array of LED RGB values.
ar = array.array("I", [0 for _ in range(NUM_LEDS)])
##########################################################################
def pixels_show():
dimmer_ar = array.array("I", [0 for _ in range(NUM_LEDS)])
for i,c in enumerate(ar):
r = int(((c >> 8) & 0xFF) * brightness)
g = int(((c >> 16) & 0xFF) * brightness)
b = int((c & 0xFF) * brightness)
dimmer_ar[i] = (g<<16) + (r<<8) + b
sm.put(dimmer_ar, 8)
time.sleep_ms(10)
def pixels_set(i, color):
ar[i] = (color[1]<<16) + (color[0]<<8) + color[2]
def pixels_fill(color):
for i in range(len(ar)):
pixels_set(i, color)
def color_chase(color, wait):
for i in range(NUM_LEDS):
pixels_set(i, color)
time.sleep(wait)
pixels_show()
time.sleep(0.1)
def wheel(pos):
# Input a value 0 to 255 to get a color value.
# The colours are a transition r - g - b - back to r.
if pos < 0 or pos > 255:
return (0, 0, 0)
if pos < 85:
return (255 - pos * 3, pos * 3, 0)
if pos < 170:
pos -= 85
return (0, 255 - pos * 3, pos * 3)
pos -= 170
return (pos * 3, 0, 255 - pos * 3)
def rainbow_cycle(wait):
for j in range(255):
for i in range(NUM_LEDS):
rc_index = (i * 256 // NUM_LEDS) + j
pixels_set(i, wheel(rc_index & 255))
pixels_show()
time.sleep(wait)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
YELLOW = (255, 150, 0)
GREEN = (0, 255, 0)
CYAN = (0, 255, 255)
BLUE = (0, 0, 255)
PURPLE = (180, 0, 255)
WHITE = (255, 255, 255)
COLORS = (RED, YELLOW, CYAN, GREEN, BLUE, PURPLE, WHITE)
print("fills")
for color in COLORS:
pixels_fill(color)
pixels_show()
time.sleep(0.2)
print("chases")
while True:
for color in COLORS:
color_chase(color, 0.0001)
print("rainbow")
rainbow_cycle(0)