modified for 8x8 panels
This commit is contained in:
22
ledmatrix.py
22
ledmatrix.py
@@ -9,6 +9,8 @@
|
|||||||
# e.g. a driver that implements a serial protocol running on an MCU.
|
# e.g. a driver that implements a serial protocol running on an MCU.
|
||||||
#
|
#
|
||||||
import time
|
import time
|
||||||
|
import math
|
||||||
|
|
||||||
if not hasattr(time, 'ticks_ms'):
|
if not hasattr(time, 'ticks_ms'):
|
||||||
# Emulate https://docs.pycom.io/firmwareapi/micropython/utime.html
|
# Emulate https://docs.pycom.io/firmwareapi/micropython/utime.html
|
||||||
time.ticks_ms = lambda: int(time.time()*1000)
|
time.ticks_ms = lambda: int(time.time()*1000)
|
||||||
@@ -24,6 +26,7 @@ class LedMatrix:
|
|||||||
self.fix_r = 0xff
|
self.fix_r = 0xff
|
||||||
self.fix_g = 0xff
|
self.fix_g = 0xff
|
||||||
self.fix_b = 0xc0
|
self.fix_b = 0xc0
|
||||||
|
self.panelcolumn = 8
|
||||||
if config:
|
if config:
|
||||||
if 'debug' in config:
|
if 'debug' in config:
|
||||||
self.debug = config['debug']
|
self.debug = config['debug']
|
||||||
@@ -47,6 +50,12 @@ class LedMatrix:
|
|||||||
# Initialize display
|
# Initialize display
|
||||||
self.driver.init_display(self.num_pixels)
|
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):
|
def xy_to_phys(self, x, y):
|
||||||
"""
|
"""
|
||||||
Map x,y to physical LED address after accounting for display rotation
|
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
|
# one step to the east, and then south to north, before the cycle
|
||||||
# starts over.
|
# starts over.
|
||||||
stride = self.stride
|
stride = self.stride
|
||||||
phys_addr = x*stride
|
phys_addr = ((x-1)%self.panelcolumn) + ((y-1)*self.panelcolumn) + (round_down((x-1)/self.panelcolumn) * self.panelcolumn * self.panelcolumn)
|
||||||
if x & 1:
|
#MOD(x-1;panelCol) + ((y-1)*panelCol) + (FLOOR.MATH((x-1)/panelCol;1)*panelCol*panelRow)
|
||||||
phys_addr += stride - 1 - y
|
# if x & 1:
|
||||||
else:
|
# phys_addr += stride - 1 - y
|
||||||
phys_addr += y
|
# else:
|
||||||
return phys_addr
|
# phys_addr += y
|
||||||
|
# return phys_addr
|
||||||
|
|
||||||
def get_pixel(self, x, y):
|
def get_pixel(self, x, y):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user