Added New LED Matrix Classes and json functionality

This commit is contained in:
= 2020-08-07 15:23:28 -04:00
parent 6c42f48cb2
commit 0f0df7abdd
7 changed files with 84313 additions and 10 deletions

Binary file not shown.

View file

@ -1,29 +1,68 @@
import json
import zipfile
from ledMatrix import Animation
matrixWith = 39
matrixHeight = 15
def askQuestion():
global matrixWith, matrixHeight
while True:
col = int(input("Column [0-31]: "))
if col <= 31 and col >= 0:
col = int(input("Column [0-" + str(matrixWith) + "]: "))
if col <= matrixWith and col >= 0:
break
else:
print("Column Number Must be Between 0 and 31")
print("Column Number Must be Between 0 and " + str(matrixWith))
while True:
row = int(input("Row [0-7]: "))
if row <= 7 and row >= 0:
row = int(input("Row [0-" + str(matrixHeight) + "]: "))
if row <= matrixHeight and row >= 0:
break
else:
print("Row Number Must be Between 0 and 7")
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 ((7-row) + (pcbNum * 16))
return ((matrixHeight-row) + (pcbNum * ((matrixHeight+1)*2)))
else:
return ((8 + row) + (pcbNum * 16))
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)
if __name__ == "__main__":
askQuestion()
askQuestion()
# mainMatrix = Matrix()
mainAnimation = Animation()
file = open('matrix.json', 'w')
matrixJSONData = mainAnimation.toJSON()
file.write(matrixJSONData)
file.close()
with zipfile.ZipFile('matrix.zip', 'w', zipfile.ZIP_DEFLATED) as myzip:
myzip.write('matrix.json')
# arr = bytearray(mainAnimation)
# print(arr)
# file.write(arr)

60
Code/ledMatrix.py Normal file
View file

@ -0,0 +1,60 @@
import json
class Animation:
def __init__(self):
self.matrices = []
for x in range(0, 50):
self.matrices.append(Matrix())
# def __str__(self):
# returnArray = []
# for x in range(len(self.panels)):
# returnArray.append(str(self.panels[x]))
# return str(returnArray)
def toJSON(self):
return json.dumps(self, default=lambda o: o.__dict__,
sort_keys=True, indent=4)
class Matrix:
def __init__(self):
self.panels = []
for x in range(0, 20):
self.panels.append(Panel())
# def __str__(self):
# returnArray = []
# for x in range(len(self.panels)):
# returnArray.append(str(self.panels[x]))
# return str(returnArray)
class Panel:
def __init__(self):
self.leds = []
for x in range(0, 16):
self.leds.append(LED())
# def __str__(self):
# returnArray = []
# for x in range(len(self.leds)):
# returnArray.append(str(self.leds[x]))
# return str(returnArray)
class LED:
def __init__(self):
self.r = 0
self.g = 0
self.b = 0
# def value(self):
# return self.r, self, g, self.b
# def __str__(self):
# return "r:" + str(self.r) + " g:" + str(self.g) + " b:" + str(self.b)
# class MatrixEncoder(JSONEncoder):
# def default(self, o):
# return o.__dict__

84204
Code/matrix.json Normal file

File diff suppressed because it is too large Load diff

BIN
Code/matrix.zip Normal file

Binary file not shown.

BIN
Electrical/render2.JPG Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 MiB

Binary file not shown.