Skip to content

Commit c55e9a1

Browse files
authored
Merge pull request #16 from adafruit/rainbowio
Update examples to use rainbowio
2 parents c31f903 + 64276b5 commit c55e9a1

File tree

2 files changed

+4
-30
lines changed

2 files changed

+4
-30
lines changed

examples/rgbled_pca9685.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import time
55
import board
66
import busio
7+
from rainbowio import colorwheel
78
import adafruit_pca9685
89
import adafruit_rgbled
910

@@ -24,24 +25,10 @@
2425
# led = adafruit_rgbled.RGBLED(RED_LED, GREEN_LED, BLUE_LED, invert_pwm=True)
2526

2627

27-
def wheel(pos):
28-
# Input a value 0 to 255 to get a color value.
29-
# The colours are a transition r - g - b - back to r.
30-
if pos < 0 or pos > 255:
31-
return 0, 0, 0
32-
if pos < 85:
33-
return int(255 - pos * 3), int(pos * 3), 0
34-
if pos < 170:
35-
pos -= 85
36-
return 0, int(255 - pos * 3), int(pos * 3)
37-
pos -= 170
38-
return int(pos * 3), 0, int(255 - (pos * 3))
39-
40-
4128
def rainbow_cycle(wait):
4229
for i in range(255):
4330
i = (i + 1) % 256
44-
led.color = wheel(i)
31+
led.color = colorwheel(i)
4532
time.sleep(wait)
4633

4734

examples/rgbled_simpletest.py

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

44
import time
55
import board
6+
from rainbowio import colorwheel
67
import adafruit_rgbled
78

89
# Pin the Red LED is connected to
@@ -21,24 +22,10 @@
2122
# led = adafruit_rgbled.RGBLED(RED_LED, GREEN_LED, BLUE_LED, invert_pwm=True)
2223

2324

24-
def wheel(pos):
25-
# Input a value 0 to 255 to get a color value.
26-
# The colours are a transition r - g - b - back to r.
27-
if pos < 0 or pos > 255:
28-
return 0, 0, 0
29-
if pos < 85:
30-
return int(255 - pos * 3), int(pos * 3), 0
31-
if pos < 170:
32-
pos -= 85
33-
return 0, int(255 - pos * 3), int(pos * 3)
34-
pos -= 170
35-
return int(pos * 3), 0, int(255 - (pos * 3))
36-
37-
3825
def rainbow_cycle(wait):
3926
for i in range(255):
4027
i = (i + 1) % 256
41-
led.color = wheel(i)
28+
led.color = colorwheel(i)
4229
time.sleep(wait)
4330

4431

0 commit comments

Comments
 (0)