Skip to content

Commit cb920b2

Browse files
authored
Merge pull request #1838 from kattni/rainbowio
Move to rainbowio
2 parents 18dbbc4 + 4719772 commit cb920b2

File tree

72 files changed

+171
-860
lines changed
  • 3D_Printed_LED_Microphone_Flag
  • 3D_Printed_Unicorn_Horn
  • Adafruit_FunHouse/dotstar_rainbow
  • Adafruit_Neo_Trinkey/cap_touch_neopixel_brightness
  • Adafruit_Prop_Maker_FeatherWing
    • Prop_Maker_3W_LED_Simpletest
    • Prop_Maker_NeoPixel_Simpletest
  • Animated_NeoPixel_Glow_Fur_Scarf
  • Black_Lives_Matter_Kit
  • CP101_StateMachines
  • CircuitPlayground_Christmas_Tree
  • CircuitPython_AT_Hand_Raiser
  • CircuitPython_Display_Text/colormask_example
  • CircuitPython_Essentials
  • CircuitPython_Heart_Sculpture
  • CircuitPython_Pico_PIO_Neopixel
  • CircuitPython_Quick_Starts
  • CircuitPython_RGBMatrix/scroller
  • CircuitPython_Templates
    • status_led_one_neopixel_rainbow
    • status_multi_dotstar_rainbow
  • Crickits/carousel
  • Cyberpunk_Spikes
  • Disco_Tie
  • Gemma_Hoop_Earrings
  • Gemma_LightTouch/gemma_lighttouch
  • Getting_Started_With_Raspberry_Pi_Pico/neopixels_rainbow
  • Hacking_Ikea_Lamps_With_CPX
  • Introducing_CircuitPlaygroundExpress
    • CircuitPlaygroundExpress_NeoPixel
    • CircuitPlaygroundExpress_Neopixel_cpx
  • Introducing_Gemma_M0
  • ItsyBitsy_Heart_Necklace
  • ItsyBitsy_Infinity_Collar
  • LED_Masquerade_Masks/NeoPixel_Gemma_Mask
  • LED_Snowboard
  • Labo_Piano_Light_FX
  • Make_It_Glow_With_Crickit
  • Music_Box_with_Crickit
  • NY_Ball_Drop
  • NeoPixel_Basketball_Hoop
    • NeoPixel_Basketball_Hoop
    • NeoPixel_Basketball_Hoop-Point_Sensor
  • NeoPixel_Jewel_10_Minute_Necklace
  • NeoPixel_Punk_Collar
  • NeoTrellis_M4_Grains_of_Sand
  • NeoTrellis_M4_Memory_Game
  • NeoTrellis_M4_Simple_Drum_Machine
  • NeoTrinkey_Zoom_Shortcuts
  • PaperCraft_Gems
  • Pixel_Chase_Game
  • Playa_Bike
  • Pumpkin_Theremin
  • PyLeap_NeoPixel_demo
  • PyRuler_Simon_Game
  • QT_Py_Bracelet
  • QT_Py_NeoPixels
  • Rotary_Trinkey/CircuitPython_ColorPicker_Example
  • Sound_Reactive_NeoPixel_Peace_Pendant
  • Textile_Potentiometer_Hoodie
  • TrellisM4_Simple_MIDI_UART
  • Ukulele
  • raver_bandolier
  • ulab_Crunch_Numbers_Fast/ledwave

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+171
-860
lines changed

3D_Printed_LED_Microphone_Flag/code.py

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import board
3333
import neopixel
34+
from rainbowio import colorwheel
3435
from analogio import AnalogIn
3536

3637
n_pixels = 16 # Number of pixels you are using
@@ -53,21 +54,6 @@
5354
strip = neopixel.NeoPixel(led_pin, n_pixels, brightness=1, auto_write=False)
5455

5556

56-
def wheel(pos):
57-
# Input a value 0 to 255 to get a color value.
58-
# The colours are a transition r - g - b - back to r.
59-
if pos < 0 or pos > 255:
60-
return (0, 0, 0)
61-
if pos < 85:
62-
return (int(pos * 3), int(255 - (pos * 3)), 0)
63-
elif pos < 170:
64-
pos -= 85
65-
return (int(255 - pos * 3), 0, int(pos * 3))
66-
else:
67-
pos -= 170
68-
return (0, int(pos * 3), int(255 - pos * 3))
69-
70-
7157
def remapRange(value, leftMin, leftMax, rightMin, rightMax):
7258
# this remaps a value fromhere original (left) range to new (right) range
7359
# Figure out how 'wide' each range is
@@ -168,7 +154,7 @@ def drawLine(fromhere, to):
168154

169155
# Fill the strip with rainbow gradient
170156
for i in range(0, len(strip)):
171-
strip[i] = wheel(remapRange(i, 0, (n_pixels - 1), 30, 150))
157+
strip[i] = colorwheel(remapRange(i, 0, (n_pixels - 1), 30, 150))
172158

173159
# Scale the input logarithmically instead of linearly
174160
c = fscale(input_floor, input_ceiling, (n_pixels - 1), 0, peaktopeak, 2)
@@ -182,7 +168,7 @@ def drawLine(fromhere, to):
182168

183169
# Set the peak dot to match the rainbow gradient
184170
y = n_pixels - peak
185-
strip.fill = (y - 1, wheel(remapRange(y, 0, (n_pixels - 1), 30, 150)))
171+
strip.fill = (y - 1, colorwheel(remapRange(y, 0, (n_pixels - 1), 30, 150)))
186172
strip.write()
187173

188174
# Frame based peak dot animation

3D_Printed_Unicorn_Horn/code.py

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import board
44
import neopixel
5+
from rainbowio import colorwheel
56
from digitalio import DigitalInOut, Direction
67

78
pixpin = board.D1
@@ -13,34 +14,19 @@
1314
strip = neopixel.NeoPixel(pixpin, numpix, brightness=1, auto_write=True)
1415

1516

16-
def wheel(pos):
17-
# Input a value 0 to 255 to get a color value.
18-
# The colours are a transition r - g - b - back to r.
19-
if (pos < 0) or (pos > 255):
20-
return (0, 0, 0)
21-
if pos < 85:
22-
return (int(pos * 3), int(255 - (pos*3)), 0)
23-
elif pos < 170:
24-
pos -= 85
25-
return (int(255 - pos * 3), 0, int(pos * 3))
26-
else:
27-
pos -= 170
28-
return (0, int(pos * 3), int(255 - pos * 3))
29-
30-
3117
def rainbow_cycle(wait):
3218
for j in range(255 * 5):
3319
for i in range(len(strip)):
3420
idx = int((i * 256 / len(strip)) + j)
35-
strip[i] = wheel(idx & 255)
21+
strip[i] = colorwheel(idx & 255)
3622
time.sleep(wait)
3723

3824

3925
def rainbow(wait):
4026
for j in range(255):
4127
for i in range(len(strip)):
4228
idx = int(i + j)
43-
strip[i] = wheel(idx & 255)
29+
strip[i] = colorwheel(idx & 255)
4430
time.sleep(wait)
4531

4632

Adafruit_FunHouse/dotstar_rainbow/code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import time
33
import board
44
import adafruit_dotstar
5-
from _pixelbuf import colorwheel
5+
from rainbowio import colorwheel
66

77
dots = adafruit_dotstar.DotStar(board.DOTSTAR_CLOCK, board.DOTSTAR_DATA, 5, auto_write=False)
88
dots.brightness = 0.3

Adafruit_Neo_Trinkey/cap_touch_neopixel_brightness/code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import board
44
import touchio
55
import neopixel
6-
from _pixelbuf import colorwheel
6+
from rainbowio import colorwheel
77

88
touch1 = touchio.TouchIn(board.TOUCH1)
99
touch2 = touchio.TouchIn(board.TOUCH2)
Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Simple rainbow swirl example for 3W LED"""
22
import pwmio
33
import board
4+
from rainbowio import colorwheel
45
import digitalio
56

67
enable = digitalio.DigitalInOut(board.D10)
@@ -11,24 +12,9 @@
1112
green = pwmio.PWMOut(board.D12, duty_cycle=0, frequency=20000)
1213
blue = pwmio.PWMOut(board.D13, duty_cycle=0, frequency=20000)
1314

14-
15-
def wheel(pos):
16-
# Input a value 0 to 255 to get a color value.
17-
# The colours are a transition r - g - b - back to r.
18-
if pos < 0 or pos > 255:
19-
return (0, 0, 0)
20-
if pos < 85:
21-
return (255 - pos * 3, pos * 3, 0)
22-
if pos < 170:
23-
pos -= 85
24-
return (0, 255 - pos * 3, pos * 3)
25-
pos -= 170
26-
return (pos * 3, 0, 255 - pos * 3)
27-
28-
2915
while True:
3016
for i in range(255):
31-
r, g, b = wheel(i)
17+
r, g, b = colorwheel(i)
3218
red.duty_cycle = int(r * 65536 / 256)
3319
green.duty_cycle = int(g * 65536 / 256)
3420
blue.duty_cycle = int(b * 65536 / 256)
Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Simple rainbow example for 30-pixel NeoPixel strip"""
22
import digitalio
33
import board
4+
from rainbowio import colorwheel
45
import neopixel
56

67
NUM_PIXELS = 30 # NeoPixel strip length (in pixels)
@@ -11,21 +12,6 @@
1112

1213
strip = neopixel.NeoPixel(board.D5, NUM_PIXELS, brightness=1)
1314

14-
15-
def wheel(pos):
16-
# Input a value 0 to 255 to get a color value.
17-
# The colours are a transition r - g - b - back to r.
18-
if pos < 0 or pos > 255:
19-
return (0, 0, 0)
20-
if pos < 85:
21-
return (255 - pos * 3, pos * 3, 0)
22-
if pos < 170:
23-
pos -= 85
24-
return (0, 255 - pos * 3, pos * 3)
25-
pos -= 170
26-
return (pos * 3, 0, 255 - pos * 3)
27-
28-
2915
while True:
3016
for i in range(255):
31-
strip.fill((wheel(i)))
17+
strip.fill((colorwheel(i)))

Animated_NeoPixel_Glow_Fur_Scarf/code.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,6 @@
6363
0xFFFF33, 0xFFFF66, 0xFFFF99, 0xFFFFCC]
6464

6565

66-
def wheel(pos):
67-
# Input a value 0 to 255 to get a color value.
68-
# The colours are a transition r - g - b - back to r.
69-
if (pos < 0) or (pos > 255):
70-
return (0, 0, 0)
71-
if pos < 85:
72-
return (int(pos * 3), int(255 - (pos * 3)), 0)
73-
elif pos < 170:
74-
pos -= 85
75-
return (int(255 - pos * 3), 0, int(pos * 3))
76-
else:
77-
pos -= 170
78-
return (0, int(pos * 3), int(255 - pos * 3))
79-
80-
8166
def remapRange(value, leftMin, leftMax, rightMin, rightMax):
8267
# this remaps a value fromhere original (left) range to new (right) range
8368
# Figure out how 'wide' each range is

Black_Lives_Matter_Kit/Capacitive_Touch_and_NeoPixels/code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import touchio
44
import digitalio
55
import neopixel
6-
from adafruit_pypixelbuf import colorwheel
6+
from rainbowio import colorwheel
77

88
pixels = neopixel.NeoPixel(board.NEOPIXEL, 6, auto_write=False)
99
red_led = digitalio.DigitalInOut(board.D13)

Black_Lives_Matter_Kit/Sound_Reactive_NeoPixels/code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import board
44
import audiobusio
55
import neopixel
6-
from adafruit_pypixelbuf import colorwheel
6+
from rainbowio import colorwheel
77

88
# Increase this number to use this example in louder environments. As you increase the number, it
99
# increases the level of sound needed to change the color of the LEDs. 5 is good for quiet up to

CP101_StateMachines/brute-force/code.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import audioio
2424
import audiocore
2525
import pwmio
26+
from rainbowio import colorwheel
2627
from adafruit_motor import servo
2728
import neopixel
2829
from adafruit_debouncer import Debouncer
@@ -131,30 +132,18 @@ def random_color():
131132
blue = random_color_byte()
132133
return (red, green, blue)
133134

134-
# Color cycling.
135-
136-
def wheel(pos):
137-
# Input a value 0 to 255 to get a color value.
138-
# The colours are a transition r - g - b - back to r.
139-
if pos < 0 or pos > 255:
140-
return 0, 0, 0
141-
if pos < 85:
142-
return int(255 - pos*3), int(pos*3), 0
143-
if pos < 170:
144-
pos -= 85
145-
return 0, int(255 - pos*3), int(pos*3)
146-
pos -= 170
147-
return int(pos * 3), 0, int(255 - (pos*3))
148135

136+
# Color cycling.
149137
def cycle_sequence(seq):
150138
while True:
151139
for elem in seq:
152140
yield elem
153141

142+
154143
def rainbow_lamp(seq):
155144
g = cycle_sequence(seq)
156145
while True:
157-
strip.fill(wheel(next(g)))
146+
strip.fill(colorwheel(next(g)))
158147
strip.show()
159148
yield
160149

CP101_StateMachines/classes/code.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import audioio
2424
import audiocore
2525
import pwmio
26+
from rainbowio import colorwheel
2627
from adafruit_motor import servo
2728
import neopixel
2829
from adafruit_debouncer import Debouncer
@@ -113,19 +114,6 @@ def random_color():
113114

114115
# Color cycling.
115116

116-
def wheel(pos):
117-
# Input a value 0 to 255 to get a color value.
118-
# The colours are a transition r - g - b - back to r.
119-
if pos < 0 or pos > 255:
120-
return 0, 0, 0
121-
if pos < 85:
122-
return int(255 - pos*3), int(pos*3), 0
123-
if pos < 170:
124-
pos -= 85
125-
return 0, int(255 - pos*3), int(pos*3)
126-
pos -= 170
127-
return int(pos * 3), 0, int(255 - (pos*3))
128-
129117
def cycle_sequence(seq):
130118
while True:
131119
for elem in seq:
@@ -134,7 +122,7 @@ def cycle_sequence(seq):
134122
def rainbow_lamp(seq):
135123
g = cycle_sequence(seq)
136124
while True:
137-
strip.fill(wheel(next(g)))
125+
strip.fill(colorwheel(next(g)))
138126
strip.show()
139127
yield
140128

CircuitPlayground_Christmas_Tree/code.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@
2323
pixel_order=ORDER)
2424

2525

26-
def wheel(pos):
26+
def colorwheel(pos):
2727
# Input a value 0 to 255 to get a color value.
2828
# The colours are a transition r - g - b - back to r.
29+
# Works with RGB or RGBW LEDs.
2930
if pos < 0 or pos > 255:
3031
r = g = b = 0
3132
elif pos < 85:
@@ -49,7 +50,7 @@ def rainbow_swirl(wait):
4950
for j in range(255):
5051
for i in range(num_pixels):
5152
pixel_index = (i * 256 // num_pixels) + j
52-
pixels[i] = wheel(pixel_index & 255)
53+
pixels[i] = colorwheel(pixel_index & 255)
5354
pixels.show()
5455
time.sleep(wait)
5556

@@ -58,7 +59,7 @@ def rainbow_fill(wait):
5859
for j in range(255):
5960
for i in range(num_pixels):
6061
pixel_index = int(i + j)
61-
pixels[i] = wheel(pixel_index & 255)
62+
pixels[i] = colorwheel(pixel_index & 255)
6263
pixels.show()
6364
time.sleep(wait)
6465

CircuitPython_AT_Hand_Raiser/code.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from time import sleep
1010
import board
11+
from rainbowio import colorwheel
1112
import adafruit_dotstar
1213
import supervisor
1314

@@ -66,19 +67,6 @@ def hex2rgb(hex_code):
6667

6768
mode='wheel'
6869

69-
# standard function to rotate around the colorwheel
70-
def wheel(cpos):
71-
# Input a value 0 to 255 to get a color value.
72-
# The colours are a transition r - g - b - back to r.
73-
if cpos < 85:
74-
return (int(cpos * 3), int(255 - (cpos * 3)), 0)
75-
elif cpos < 170:
76-
cpos -= 85
77-
return (int(255 - (cpos * 3)), 0, int(cpos * 3))
78-
else:
79-
cpos -= 170
80-
return (0, int(cpos * 3), int(255 - cpos * 3))
81-
8270
# We start by turning off pixels
8371
pixels.fill(black)
8472
pixels.show()
@@ -148,7 +136,7 @@ def wheel(cpos):
148136
elif mode == 'wheel':
149137
sleep(.05)
150138
pos = (pos + 1) % 255
151-
pixels.fill(wheel(pos))
139+
pixels.fill(colorwheel(pos))
152140
pixels.show()
153141
elif mode == 'solid':
154142
pixels.fill(targetColor)

CircuitPython_Display_Text/colormask_example/code.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,10 @@
88

99
import board
1010
import displayio
11+
from rainbowio import colorwheel
1112
from adafruit_bitmap_font import bitmap_font
1213
from adafruit_display_text import bitmap_label as label
1314

14-
15-
def wheel(pos):
16-
# input a value 0 to 255 to get a color value
17-
# the colors are a transition r-g-b-back to r.
18-
if pos < 1 or pos > 255:
19-
return (0, 0, 0)
20-
if pos < 85:
21-
return (255 - pos * 3, pos * 3, 0)
22-
if pos < 170:
23-
pos -= 85
24-
return (0, 255 - pos * 3, pos * 3)
25-
pos -= 170
26-
return (pos * 3, 0, 255 - pos * 3)
27-
28-
2915
# Make the display context. Change size if you want
3016
display = board.DISPLAY
3117

@@ -58,7 +44,7 @@ def wheel(pos):
5844
rainbow_palette = displayio.Palette(255)
5945

6046
for i in range(0, 255):
61-
rainbow_palette[i] = int("".join("%02x" % i for i in wheel(i)), 16)
47+
rainbow_palette[i] = int("".join("%02x" % i for i in colorwheel(i)), 16)
6248

6349
for y in range(rainbow_bitmap.height):
6450
for x in range(rainbow_bitmap.width):

0 commit comments

Comments
 (0)