From 4f4cbde2bfa5ed08c7a977d62fe479c85119096a Mon Sep 17 00:00:00 2001 From: Willem Date: Thu, 7 Jan 2021 10:42:20 +0100 Subject: [PATCH] modified for 8x8 panels --- ledmatrix.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/ledmatrix.py b/ledmatrix.py index 34c29e4..889f6c4 100755 --- a/ledmatrix.py +++ b/ledmatrix.py @@ -9,6 +9,8 @@ # e.g. a driver that implements a serial protocol running on an MCU. # import time +import math + if not hasattr(time, 'ticks_ms'): # Emulate https://docs.pycom.io/firmwareapi/micropython/utime.html time.ticks_ms = lambda: int(time.time()*1000) @@ -24,6 +26,7 @@ class LedMatrix: self.fix_r = 0xff self.fix_g = 0xff self.fix_b = 0xc0 + self.panelcolumn = 8 if config: if 'debug' in config: self.debug = config['debug'] @@ -47,6 +50,12 @@ class LedMatrix: # Initialize display self.driver.init_display(self.num_pixels) + def round_down(self, n, decimals=0): + multiplier = 10 ** decimals + return math.floor(n * multiplier) / multiplier + + + def xy_to_phys(self, x, y): """ Map x,y to physical LED address after accounting for display rotation @@ -68,12 +77,13 @@ class LedMatrix: # one step to the east, and then south to north, before the cycle # starts over. stride = self.stride - phys_addr = x*stride - if x & 1: - phys_addr += stride - 1 - y - else: - phys_addr += y - return phys_addr + phys_addr = ((x-1)%self.panelcolumn) + ((y-1)*self.panelcolumn) + (round_down((x-1)/self.panelcolumn) * self.panelcolumn * self.panelcolumn) + #MOD(x-1;panelCol) + ((y-1)*panelCol) + (FLOOR.MATH((x-1)/panelCol;1)*panelCol*panelRow) + # if x & 1: + # phys_addr += stride - 1 - y + # else: + # phys_addr += y + # return phys_addr def get_pixel(self, x, y): """