Skip to content
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

Add toggle demo. #12

Merged
merged 2 commits into from
Nov 9, 2018
Merged
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
45 changes: 45 additions & 0 deletions examples/trellism4_neopixel_toggle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import adafruit_trellism4

trellis = adafruit_trellism4.TrellisM4Express()


def wheel(pos):
if pos < 0 or pos > 255:
return 0, 0, 0
if pos < 85:
return int(255 - pos * 3), int(pos * 3), 0
if pos < 170:
pos -= 85
return 0, int(255 - pos * 3), int(pos * 3)
pos -= 170
return int(pos * 3), 0, int(255 - (pos * 3))


led_on = []

for x in range(trellis.pixels.width):
led_on.append([])
for y in range(trellis.pixels.height):
led_on[x].append(False)

trellis.pixels.fill((0, 0, 0))

current_press = set()

while True:
pressed = set(trellis.pressed_keys)

for press in pressed - current_press:
x, y = press
if not led_on[x][y]:
print("Turning on:", press)
pixel_index = ((x + (y * 8)) * 256 // 32)
trellis.pixels[x, y] = wheel(pixel_index & 255)
led_on[x][y] = True

else:
print("Turning off:", press)
trellis.pixels[x, y] = (0, 0, 0)
led_on[x][y] = False

current_press = pressed