Skip to content

Commit 4719772

Browse files
committed
Move to rainbowio
1 parent 18dbbc4 commit 4719772

72 files changed

Lines changed: 171 additions & 860 deletions

File tree

  • 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-Point_Sensor
    • NeoPixel_Basketball_Hoop
  • 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.

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

0 commit comments

Comments
 (0)