From 4655ddf9e31f1c15a188c5f8e9f0d7ee3c29afdf Mon Sep 17 00:00:00 2001 From: Lohni Date: Mon, 21 Mar 2022 18:58:03 +0100 Subject: [PATCH] text rotation #2 --- ESP32/LEDUtils.py | 47 ++++++++++++++++++++++++++++++++++------------- ESP32/LedMain.py | 2 +- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/ESP32/LEDUtils.py b/ESP32/LEDUtils.py index 9b5a62f..3119969 100644 --- a/ESP32/LEDUtils.py +++ b/ESP32/LEDUtils.py @@ -12,6 +12,9 @@ # | | | # 12 - 13 - 14 # +import time + +import uasyncio font = { "A": [1, 3, 5, 6, 7, 8, 9, 11, 12, 14], @@ -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], @@ -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)) @@ -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 @@ -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)) diff --git a/ESP32/LedMain.py b/ESP32/LedMain.py index efed96a..74ef318 100644 --- a/ESP32/LedMain.py +++ b/ESP32/LedMain.py @@ -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))