Skip to content

Fixed 0/180 rotation coordinates #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions adafruit_trellism4.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ def __init__(self, pin, *, width, height, rotation=0):
def __setitem__(self, index, value):
if not isinstance(index, tuple) or len(index) != 2:
raise IndexError("Index must be tuple")
if index[0] >= self.width or index[1] >= self.height:
raise IndexError("Pixel assignment outside available coordinates.")

if self._rotation == 0 or self._rotation == 180:
offset = self.width * index[1] + index[0]
Expand All @@ -78,6 +80,9 @@ def __setitem__(self, index, value):
elif self._rotation == 90:
offset = self.height * (self.width - index[0] - 1) + index[1]

if offset < 0:
raise IndexError("Pixel assignment outside available coordinates.")

self._neopixel[offset] = value
self._neopixel.show()

Expand Down Expand Up @@ -267,9 +272,9 @@ def __init__(self, rotation=0):
row = []
for x in range(4):
if rotation == 0:
coord = (x, y)
coord = (y, x)
elif rotation == 180:
coord = (3 - x, 7 - y)
coord = (7 - y, 3 - x)
elif rotation == 90:
coord = (3 - x, y)
elif rotation == 270:
Expand Down
2 changes: 1 addition & 1 deletion examples/neopixel_trellism4.simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def wheel(pos):
for press in pressed - current_press:
if press:
print("Pressed:", press)
pixel = (press[0] * 8) + press[1]
pixel = (press[1] * 8) + press[0]
pixel_index = (pixel * 256 // 32)
trellis.pixels.fill(wheel(pixel_index & 255))
for release in current_press - pressed:
Expand Down