Skip to content

Commit f30754d

Browse files
authored
Merge pull request #7 from kattni/coordinate-fix
Fixed 0/180 rotation coordinates
2 parents cbf8651 + 22ad5f9 commit f30754d

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

adafruit_trellism4.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ def __init__(self, pin, *, width, height, rotation=0):
6666
def __setitem__(self, index, value):
6767
if not isinstance(index, tuple) or len(index) != 2:
6868
raise IndexError("Index must be tuple")
69+
if index[0] >= self.width or index[1] >= self.height:
70+
raise IndexError("Pixel assignment outside available coordinates.")
6971

7072
if self._rotation == 0 or self._rotation == 180:
7173
offset = self.width * index[1] + index[0]
@@ -76,6 +78,9 @@ def __setitem__(self, index, value):
7678
elif self._rotation == 90:
7779
offset = self.height * (self.width - index[0] - 1) + index[1]
7880

81+
if offset < 0:
82+
raise IndexError("Pixel assignment outside available coordinates.")
83+
7984
self._neopixel[offset] = value
8085
self._neopixel.show()
8186

@@ -261,9 +266,9 @@ def __init__(self, rotation=0):
261266
row = []
262267
for x in range(4):
263268
if rotation == 0:
264-
coord = (x, y)
269+
coord = (y, x)
265270
elif rotation == 180:
266-
coord = (3 - x, 7 - y)
271+
coord = (7 - y, 3 - x)
267272
elif rotation == 90:
268273
coord = (3 - x, y)
269274
elif rotation == 270:

examples/neopixel_trellism4.simpletest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def wheel(pos):
3030
for press in pressed - current_press:
3131
if press:
3232
print("Pressed:", press)
33-
pixel = (press[0] * 8) + press[1]
33+
pixel = (press[1] * 8) + press[0]
3434
pixel_index = (pixel * 256 // 32)
3535
trellis.pixels.fill(wheel(pixel_index & 255))
3636
for release in current_press - pressed:

0 commit comments

Comments
 (0)