Skip to content

Commit

Permalink
text rotation #2
Browse files Browse the repository at this point in the history
  • Loading branch information
Lohni committed Mar 21, 2022
1 parent 0cefd18 commit 4655ddf
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
47 changes: 34 additions & 13 deletions ESP32/LEDUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
# | | |
# 12 - 13 - 14
#
import time

import uasyncio

font = {
"A": [1, 3, 5, 6, 7, 8, 9, 11, 12, 14],
Expand Down Expand Up @@ -46,7 +49,7 @@
"4": [0, 3, 5, 6, 7, 8, 11, 14],
"5": [0, 1, 2, 3, 6, 7, 8, 11, 12, 13, 14],
"6": [0, 1, 2, 3, 6, 7, 8, 9, 11, 12, 13, 14],
"7": [0, 1, 2, 5, 8, 11, 14],
"7": [0, 1, 2, 3, 5, 8, 11, 14],
"8": [0, 1, 2, 3, 5, 6, 7, 8, 9, 11, 12, 13, 14],
"9": [0, 1, 2, 3, 5, 6, 7, 8, 11, 12, 13, 14],
"0": [0, 1, 2, 3, 5, 6, 8, 9, 11, 12, 13, 14],
Expand All @@ -59,6 +62,7 @@
class LEDUtils:
def __init__(self, led_count: int):
self.np = neopixel.NeoPixel(machine.Pin(2), led_count)
self.rotation = 1

async def writeStringToMatrix(self, s: str):
self.np.fill((0, 0, 0))
Expand All @@ -69,6 +73,7 @@ async def writeStringToMatrix(self, s: str):

position = font.get(char)
self.writeCharToMatrix(position, pos, seperator)
self.np.write()

def writeCharToMatrix(self, char: [], char_position, seperator: bool):
# width of matrix : 32, char width : 3 + 1 padding
Expand All @@ -80,18 +85,34 @@ def writeCharToMatrix(self, char: [], char_position, seperator: bool):
# 1 led padding between letters
startIndex += char_position

for pos in char:
if pos < 3:
self.np[startIndex + pos] = (10, 5, 6)
elif pos < 6:
self.np[-startIndex + (matrixWidth * 2 - 1) + (3 - pos)] = (10, 5, 6)
elif pos < 9:
self.np[startIndex + (matrixWidth * 2) + (6 - pos) * -1] = (10, 5, 6)
elif pos < 12:
self.np[-startIndex + (matrixWidth * 4 - 1) + (9 - pos)] = (10, 5, 6)
else:
self.np[startIndex + (matrixWidth * 4) + (12 - pos) * -1] = (10, 5, 6)
self.np.write()
if self.rotation == 0:
for pos in char:
if pos < 3:
self.np[startIndex + pos] = (10, 5, 6)
elif pos < 6:
self.np[-startIndex + (matrixWidth * 2 - 1) + (3 - pos)] = (10, 5, 6)
elif pos < 9:
self.np[startIndex + (matrixWidth * 2) + (6 - pos) * -1] = (10, 5, 6)
elif pos < 12:
self.np[-startIndex + (matrixWidth * 4 - 1) + (9 - pos)] = (10, 5, 6)
else:
self.np[startIndex + (matrixWidth * 4) + (12 - pos) * -1] = (10, 5, 6)
else:
startIndex = 224 + startIndex
row_pos = matrixWidth - (256 - startIndex)
for pos in char:
if pos < 3:
self.np[startIndex + pos] = (10, 5, 6)
elif pos < 6:
self.np[startIndex - (row_pos * 2 - 1) - (pos - 3) - 2] = (10, 5, 6)
elif pos < 9:
self.np[startIndex - matrixWidth*2 + (pos - 6)] = (10, 5, 6)
elif pos < 12:
self.np[startIndex - (row_pos + matrixWidth) * 2 - 1 - (pos - 9)] = (10, 5, 6)
else:
self.np[startIndex - matrixWidth * 4 + (pos - 12)] = (10, 5, 6)

return

async def runningText(self, s, padding):
self.np.fill((0, 0, 0))
Expand Down
2 changes: 1 addition & 1 deletion ESP32/LedMain.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def run(self):
# Todo: calc color hues https://www.colorspire.com/rgb-color-wheel/

print(tmp_color)
# uasyncio.run(self.ledUtil.writeStringToMatrix(tmp))
uasyncio.run(self.ledUtil.writeStringToMatrix(tmp))

current_min = local_time[4]
print(str(current_min) + ' ... ' + str(self.persistence.last_persisted_minute))
Expand Down

0 comments on commit 4655ddf

Please sign in to comment.