Skip to content

Commit f8db46c

Browse files
authored
Merge pull request #26 from adafruit/rainbowio
Update examples to use rainbowio
2 parents 62db398 + 1000cc7 commit f8db46c

File tree

4 files changed

+8
-31
lines changed

4 files changed

+8
-31
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ repos:
3030
name: pylint (examples code)
3131
description: Run pylint rules on "examples/*.py" files
3232
entry: /usr/bin/env bash -c
33-
args: ['([[ ! -d "examples" ]] || for example in $(find . -path "./examples/*.py"); do pylint --disable=missing-docstring,invalid-name $example; done)']
33+
args: ['([[ ! -d "examples" ]] || for example in $(find . -path "./examples/*.py"); do pylint --disable=missing-docstring,invalid-name,consider-using-f-string $example; done)']
3434
language: system

examples/trellism4_neopixel_simpletest.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,15 @@
44
"""Test your Trellis M4 Express without needing the serial output.
55
Press any button and the rest will light up the same color!"""
66
import time
7+
from rainbowio import colorwheel
78
import adafruit_trellism4
89

910
trellis = adafruit_trellism4.TrellisM4Express()
1011

11-
12-
def wheel(pos):
13-
if pos < 0 or pos > 255:
14-
return 0, 0, 0
15-
if pos < 85:
16-
return int(255 - pos * 3), int(pos * 3), 0
17-
if pos < 170:
18-
pos -= 85
19-
return 0, int(255 - pos * 3), int(pos * 3)
20-
pos -= 170
21-
return int(pos * 3), 0, int(255 - (pos * 3))
22-
23-
2412
for x in range(trellis.pixels.width):
2513
for y in range(trellis.pixels.height):
2614
pixel_index = ((y * 8) + x) * 256 // 32
27-
trellis.pixels[x, y] = wheel(pixel_index & 255)
15+
trellis.pixels[x, y] = colorwheel(pixel_index & 255)
2816

2917

3018
current_press = set()
@@ -35,13 +23,13 @@ def wheel(pos):
3523
print("Pressed:", press)
3624
pixel = (press[1] * 8) + press[0]
3725
pixel_index = pixel * 256 // 32
38-
trellis.pixels.fill(wheel(pixel_index & 255))
26+
trellis.pixels.fill(colorwheel(pixel_index & 255))
3927
for release in current_press - pressed:
4028
if release:
4129
print("Released:", release)
4230
for x in range(trellis.pixels.width):
4331
for y in range(trellis.pixels.height):
4432
pixel_index = ((y * 8) + x) * 256 // 32
45-
trellis.pixels[x, y] = wheel(pixel_index & 255)
33+
trellis.pixels[x, y] = colorwheel(pixel_index & 255)
4634
time.sleep(0.08)
4735
current_press = pressed

examples/trellism4_neopixel_toggle.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,11 @@
11
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
22
# SPDX-License-Identifier: MIT
33

4+
from rainbowio import colorwheel
45
import adafruit_trellism4
56

67
trellis = adafruit_trellism4.TrellisM4Express()
78

8-
9-
def wheel(pos):
10-
if pos < 0 or pos > 255:
11-
return 0, 0, 0
12-
if pos < 85:
13-
return int(255 - pos * 3), int(pos * 3), 0
14-
if pos < 170:
15-
pos -= 85
16-
return 0, int(255 - pos * 3), int(pos * 3)
17-
pos -= 170
18-
return int(pos * 3), 0, int(255 - (pos * 3))
19-
20-
219
led_on = []
2210

2311
for x in range(trellis.pixels.width):
@@ -38,7 +26,7 @@ def wheel(pos):
3826
if not led_on[x][y]:
3927
print("Turning on:", press)
4028
pixel_index = (x + (y * 8)) * 256 // 32
41-
trellis.pixels[x, y] = wheel(pixel_index & 255)
29+
trellis.pixels[x, y] = colorwheel(pixel_index & 255)
4230
led_on[x][y] = True
4331

4432
else:

examples/trellism4_wavefile_synth/trellism4_wavefile_synth.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
It uses Mixer to play up to 7 notes at once.
88
Play notes with the rainbow buttons. Change waveform types ith the white buttons in the last column.
99
"""
10+
# pylint: disable=consider-using-with,consider-using-dict-items
1011
import board
1112
from audiocore import WaveFile
1213
from audioio import AudioOut

0 commit comments

Comments
 (0)